Solved

Redirect to first page form

Posted on 2014-03-12
8
539 Views
Last Modified: 2014-03-12
Hi there.  My WordPress site uses Gravity forms and on my site I have 2 forms.  I am passing a few parameters in the url from the first form to the second form such as email.

Now, I do not want the user to access this second page directly but only if they come via the first form page.  Is there something in functions.php or .htaccess (using http referer) or a conditional on that second form that will automatically redirect the user to that first form?

Thanks!
0
Comment
Question by:COwebmaster
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39924705
Use $_SERVER['HTTP_REFERER'];
Will give the previous page url
0
 

Author Comment

by:COwebmaster
ID: 39924714
Okay, so what would I create and which file or page?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39924735
On your second page

if($_SERVER['HTTP_REFERER']!="http://www.yoursite.com/yourpage.php"){
// what should happen if they haven't come from the previous page, redirect etc
}

Open in new window


Note everything is passed in the REFERER string including any querystring params.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:COwebmaster
ID: 39924802
okay, on my wordpress site, I installed a php plugin so I can embed php code on the page.

I've set your code but need to place the redirect line of code in there.  What would that be?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39924810
header('Location: '.$newURL);

if($_SERVER['HTTP_REFERER']!="http://www.yoursite.com/yourpage.php"){
     header('Location: newurl.php');
}
0
 

Author Comment

by:COwebmaster
ID: 39924827
Okay, I tried but the page is not redirecting. I have:

<?php
if($_SERVER['HTTP_REFERER']!="http://www.domain.com/page-1/"){
header('Location: http://www.domain.com/page-1/');
}
?>
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39924844
Should be checking it is set first...

if(!isset($_SERVER['HTTP_REFERER'])||$_SERVER['HTTP_REFERER']!="http://localhost/tt.php"){
     header('Location: http://www.domain.com/page-1/');
}

Open in new window

0
 

Author Closing Comment

by:COwebmaster
ID: 39924884
That worked, thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question