Reputation: 23
I'm very new to PHP and am creating a php contact page. Upon filling the form, you are redirected to success.php (note the contact page is index.php). I want success.php only visitable if you came from index.php. Can anyone point me in the right direction?
Upvotes: 0
Views: 101
Reputation: 16495
On a second thought, You can use PHP's Server variable called $_SERVER['HTTP_REFERER']
to check from which page a user is comming from. For example, If you have index.php
and contact.php
then, if you place echo $_SERVER['HTTP_REFERER'];
in contact.php
, everytime you visit that page, it will tell you from which page you are coming from.
So, in you case, if you wanted people to go to success.php
after ONLY filing contact.php
then you can place this in the success page.
if($_SERVER['HTTP_REFERER'] == 'contact.php') {
echo 'Success';
}else {echo 'Please go back to contact page first';}
You can learn more about $_SERVER[]
variables, here php.net/manual/en/reserved.variables.server.php
Upvotes: 1