By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

I can not make the php script to reconize a variable

P: 1
Hy.

I have a php script that should do that:
When a visitor come to my page from a referral get this referral and make a link to the domain of that referral on one of my pages. The ideea is that the link will last only the visitor is on the page

Here is the code:

if(!isset($_SESSION["origURL"])|| (trim($_SESSION["origURL"]) <> ''))
{
if ($_SERVER['HTTP_REFERER'] <>'')
{
$linkuri = $_SERVER['HTTP_REFERER'];
$x= strlen($linkuri)-7;
$linkuri = substr($linkuri,7,$x);
$x=strrpos($linkuri,"/");
$linkuri=substr($linkuri,0,$x);
$vergoogle = substr($linkuri,0,10);
$veryahoo=substr($linkuri,0,9);
if($veryahoo <> 'www.yahoo')
{
session_regenerate_id();
$_SESSION["origURL"]=$linkuri;
$link=$_SESSION["origURL"];
echo "<h3><a href='http://".$link."' target='_blank'>".$link."</a>";
session_write_close();
}
}
}
else
{
$link=$_SESSION["origURL"];
echo "<h3><a href='http://".$link."' target='_blank'>".$link."</a>";
}

The idea is that the visitor will come directly to the page with this code(mysite.ro/links), after this start surfing my website and then if he come back to the mysite.ro/links he should see it link there.

As you can see I try to use a session variable, and when he first enter my site on the page mysite.ro/links I chek if $_SESSION["origURL"], and if not set in it the domain of the referral, after this the visitor will look over my other pages, and when he come back to mystie.ro/links check again if the $_SESSION["origURL"] is sent and if yes use the for createing the link.

Tha problem is that the first I open a browser and go directly to that page from google is ok, I got the link, but after I surf to my site and get back the link got my domain and not the firs referral.

On the second visit the $_SESSION["origURL"] is not set.

Thank you
Oct 11 '11 #1
Share this Question
Share on Google+
1 Reply


P: 59
bcos on coming back to ur site the same function that assigns the referrer overrides it. so i ll suggest u wrap it in an if statement
[code]
if($_SERVER['HTTP_REFERER'] != 'mydomain.com'){

$_SESSION['origURL'] = $_SERVER['HTTP_REFERER'];
}

hope this is useful
Oct 13 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.