Jump to content

[SOLVED] Check referring page?


acctman

Recommended Posts

this is very simple: something like this:

 

PAGE 1

<?php
session_start();
$_SESSION['page_1'] = true;
echo "This is page 1";
echo '<br /><a href="page_2.php">Page 2</a>';
?>

 

PAGE 2

<?php
if (!isset($_SESSION['page_1'])){
header("Location: page_1.php");
}else{
echo "Welcome to page 2!";
}
?>

 

Hope that helps\works :P

Since 'HTTP_REFERER' is a header that is sent with the request for the page, if I was a bot script, I would simply set 'HTTP_REFERER' to be what your script is expecting and I could directly access page2 without ever visiting page1.

 

Using a session variable (something that is completely out of the hands of the visitor or bot script) is the most secure way to do this. The session variable should be unset() after you test it so that once someone (or a bot script) visits page1, they cannot repeatedly perform the action permitted on page2 without needing to go back to page1 to set the session variable again.

so did I tell him right?

 

this is very simple: something like this:

 

PAGE 1

<?php
session_start();
$_SESSION['page_1'] = true;
echo "This is page 1";
echo '<br /><a href="page_2.php">Page 2</a>';
?>

 

PAGE 2

<?php
if (!isset($_SESSION['page_1'])){
header("Location: page_1.php");
}else{
echo "Welcome to page 2!";
}
unset($_SESSION['page_1']);
?>

 

Hope that helps\works :P

so did I tell him right?

 

this is very simple: something like this:

 

PAGE 1

<?php
session_start();
$_SESSION['page_1'] = true;
echo "This is page 1";
echo '<br /><a href="page_2.php">Page 2</a>';
?>

 

PAGE 2

<?php
if (!isset($_SESSION['page_1'])){
header("Location: page_1.php");
}else{
echo "Welcome to page 2!";
}
unset($_SESSION['page_1']);
?>

 

Hope that helps\works :P

 

thanks. and thanks to everyone who posted. About "unset" when should that be used? unset is new to me

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.