PDA

View Full Version : Simple PHP Help +rep



iUnknown
27-02-2008, 06:28 PM
Hello,

Basically, I need to make a script that shows certain code "if" you have "HTTP_REFERER" of index.php, but "else" you get redirected to index.php. I need it to work in as many internet browsers as possible but just internet explorer is fine.

I have had a go at it myself but can't seem to actually get it working.

Here are snippets of code:

index.inc.php:


<?

$_httpreferer = $_SERVER['HTTP_REFERER'];
if ($_httpreferer == "index.php") {

?>At the end of the content on index.inc.php....


<?php
}
else {
header("Location: index.php");
}
?>


Errors:



Notice: Undefined index: HTTP_REFERER in /home/youngmus/public_html/browse/index.inc.php on line 3

Notice: Undefined variable: _httpreferer in /home/youngmus/public_html/browse/index.inc.php on line 3

Notice: Undefined variable: _httpreferer in /home/youngmus/public_html/browse/index.inc.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /home/youngmus/public_html/browse/index.inc.php:3) in /home/youngmus/public_html/browse/index.inc.php on line 126


Any ideas on how to get it to work?

MrCraig
27-02-2008, 06:34 PM
Try..



<?php
$ref = $_SERVER['HTTP_REFERER']
if(eregi("index.php",$ref))
{
/*
Referrer is index.php
*/
}
else
{
echo('<meta http-equiv="refresh" content="0;url=index.php" />');
}
?>

sgraham
27-02-2008, 06:38 PM
If all else fails, you could try setting a session when they visit the index page, and if that session is not set then redirect them to the index page.

Good luck.

MrCraig
27-02-2008, 06:50 PM
Sorry, spotted error.




<?php
$ref = $_SERVER['HTTP_REFERER'];
if(eregi("index.php",$ref))
{
/*
Referrer is index.php
*/
}
else
{
echo('<meta http-equiv="refresh" content="0;url=index.php" />');
}
?>

iUnknown
27-02-2008, 06:57 PM
Still not working, but less errors:


Notice: Undefined index: HTTP_REFERER in /home/youngmus/public_html/browse/index.inc.php on line 3

Plus, it redirects to index.php.

MrCraig
27-02-2008, 07:02 PM
By Sessions..

On your index.php page put at the very top of code:


<?php
session_start();
$_SESSION["ads"] = 1;
?>


Then in your redirect page, put in, at very top again


<?php
session_start();
if(!isset($_SESSION["ads"]))
die('<meta http-equiv="refresh" content="0;url=index.php" />');
?>

iUnknown
27-02-2008, 07:10 PM
Hooray it works perfectly - and amazingly! Just what I wanted, very pleased thank you.

+rep and a special gift that I didn't say at the beginning just because you always help me :)

Want to hide these adverts? Register an account for free!