Solved

Redirect to first page form

Posted on 2014-03-12
8
535 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to dynamically set the form action using jQuery.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now