Hi guys,

I am still kind of struggeling with my upgrade from php4 to php5, my site is almost there but I can't figure out how to set my http_referer.

This is how it looks like today:

<?php
 $_SESSION["referer"] .= $_SERVER['HTTP_REFERER'];
 $my_web = $_SESSION["referer"]
?>

The error message I get is "undefined variable: _SESSION and undefined index: referer".

I have tried to put isset() everywhere, but I can not figure out the soulution.

Any suggestions? :)

Recommended Answers

All 6 Replies

Your script should be the following:

<?php session_start();
 $_SESSION["referer"] .= $_SERVER['HTTP_REFERER'];
 $my_web = $_SESSION["referer"]
?>

Also you will need to find another alternative to $_SERVER as it isn't always that accurate. The reason being is users can disable that information being sent.

Thanks for the suggestion, but it still doesn't work. I still get the same undefined variable/index errors :(

Ow now I see. Another bug. Try this.

<?php session_start();
if (!isset($_SESSION['referer']) { 
    $_SESSION['referer']='';
    }
$_SESSION['referer'].=$_SERVER['HTTP_REFERER']."\n";
$my_web = $_SESSION['referer']
?>

I think it's something along these lines i need. But now i got an error saying "unexpexted '{' in line 2". When i take the '{' away, obviously I get an other error. I also tried to mix up the code a little, but i still can't get it right.

OMG these bugs keep on coming. Did you hide any more for me to fix?

<?php session_start();
if (!isset($_SESSION['referer'])) { 
    $_SESSION['referer']='';
    }
$_SESSION['referer'].=(isset($_SERVER['HTTP_REFERER']))?($_SERVER['HTTP_REFERER']."\n"):'';
$my_web = $_SESSION['referer'];
?>

This time I tested it :)

Thank you so much! Now it work's perfectly :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.