Solved

Redirect to first page form

Posted on 2014-03-12
8
540 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn how to count occurrences of each item in an array.
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.

808 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