Hi I have been trying to show different telephone numbers per referrer through out all site pages, the script i have hashed together is below, it works and checks referrer then displays the correct number, how ever upon clicking internal links within my site the new referrer is then my site so it then shows the default.
There must be away to store and use the original referrer, then show a message accross all site pages quoting the referrer relevant number.
Many thanks to anyone that can help
<?PHP
session_start();
if (isset($_SESSION['referrer'])) {
$referrer = $_SESSION['referrer'];
} else {
$referrer = strtolower($_SERVER["HTTP_REFERER"]);
}
if (strstr($referer,"essential"))
{
echo("<h1>Telephone Number1</h1>");
}
else if (strstr($referer,"site2"))
{
echo("<h1>Telephone Number2</h1>");
}
else if (strstr($referer,"site3"))
{
echo("<h1>Telephone Number3</h1>");
}
else if (strstr($referer,"site4"))
{
echo("<h1>Telephone Number4</h1>");
}
else
{
echo("<h1>Telephone Number5</h1>");
} $_SESSION[’referrer’] = $referrer; // store session data
?>
Help with PHP Sessions and Referrer
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Help with PHP Sessions and Referrer
You're setting the session var on every page load. I just moved that one line so that you only set the session var if it's not already set. Hope it works.
Code: Select all
session_start();
if (isset($_SESSION['referrer'])) {
$referrer = $_SESSION['referrer'];
} else {
$referrer = strtolower($_SERVER["HTTP_REFERER"]);
$_SESSION['referrer'] = $referrer; // store session data
}
if (strstr($referer,"essential"))
{
echo("<h1>Telephone Number1</h1>");
}
else if (strstr($referer,"site2"))
{
echo("<h1>Telephone Number2</h1>");
}
else if (strstr($referer,"site3"))
{
echo("<h1>Telephone Number3</h1>");
}
else if (strstr($referer,"site4"))
{
echo("<h1>Telephone Number4</h1>");
}
else
{
echo("<h1>Telephone Number5</h1>");
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Help with PHP Sessions and Referrer
No unfortunately that has now stopped the number changing all together and the relevant referrer number does not show defaulting to the last else / echo
Any more thoughts welcome
Any more thoughts welcome
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Help with PHP Sessions and Referrer
Currently, if someone comes to your page from a referrer (another link) then it sets that as a session var. If then they click on internal links within your site it doesn't replace the session var. You either have the initial referrer or you have a new referrer every time you click a link, unless you can give more conditions that can be met.dremes wrote:No unfortunately that has now stopped the number changing all together and the relevant referrer number does not show defaulting to the last else / echo
Any more thoughts welcome
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Help with PHP Sessions and Referrer
For what I posted to work, you're going to have to clear your cookie and restart your browser since you already have a session var set from previous attempts. If not, then I guess I'm still fuzzy on what you want to happen.
-Shawn
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Help with PHP Sessions and Referrer
Hi Shawn,
Many thanks for your help so far,
I am aiming to change the telephone number in the header of site depending upon where the referral came from
IF came from site A > Mysite Display Number 00001 through all my site pages
IF came from site B > Mysite Display Number 00002 through all my site pages
IF came from site c > Mysite Display Number 00003 through all my site pages
I can make this happen with the original script i posted but upon internal link clicking the new referrer becomes mysite there for fouls everything.
I am more then happy to send over some beer money to whom who resolves this one!!!
Many thanks for your help so far,
I am aiming to change the telephone number in the header of site depending upon where the referral came from
IF came from site A > Mysite Display Number 00001 through all my site pages
IF came from site B > Mysite Display Number 00002 through all my site pages
IF came from site c > Mysite Display Number 00003 through all my site pages
I can make this happen with the original script i posted but upon internal link clicking the new referrer becomes mysite there for fouls everything.
I am more then happy to send over some beer money to whom who resolves this one!!!
Re: Help with PHP Sessions and Referrer
cleared browser history inc cookies shall try again in different broswerAbraCadaver wrote:For what I posted to work, you're going to have to clear your cookie and restart your browser since you already have a session var set from previous attempts. If not, then I guess I'm still fuzzy on what you want to happen.
-Shawn