Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Redirect to first page form

Posted on 2014-03-12
8
Medium Priority
?
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 

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 2000 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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 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