Jump to content

Cookies or Session


rhouk

Recommended Posts

I have a dynamically generated website that needs for a phone number (include file) to change depending on which page they entered on.  These pages are clones of the index.php page, but seperated into their own folder, so URL can be used in seperate magazine ads and are easily distinguishable.

 

http://www.francoisandco.com/

http://www.francoisandco.com/ad/

http://www.francoisandco.com/elle/

http://www.francoisandco.com/fd/

http://www.francoisandco.com/ch/

etc.

 

Each page will have a unique phone number at the top of the page.  Once they enter, through one of these advertised URLs, any link will send them back into the main content area. 

 

What I'm trying to accomplish is for the browser to recognize where they entered  (....andco.com/ad/ or ....andco.com/elle/) and use that information to tell the main page which phone number to display.

 

Using the following code on the main index.php page accomplishes this, but only on the initial click from the entrance page.

 

if(getenv('HTTP_REFERER') == "http://www.francoisandco.com/ad/") { $phone = "AD"; }

if(!isset($phone)) $phone="main";

 

and using the following in the include file:

 

<img src="/images/phoneNumber-<? echo $phone; ?>.jpg" width="250" height="60" border="0" alt="Call Today!">

 

And then creating seperate phone number images with associated names (phoneNumber-AD.jpg, phoneNumber-ELLE.jpg, etc.).

 

Anyway, since the refering page changes on the next click, this reverts back to the "main" phone number, but I need the phone number to remain associated with the page they entered on.  So I'm thinking Cookies and/or Sessions would be a solution, but have not used them before so not sure how to set this up.

 

Sorry for the drawn out explanation, but thought it might help. 

 

Any initial thoughts on using Cookies and/or Sessions to accomplish this?  Any threads or tutorials that might help? 

 

Many thanks!!

Link to comment
Share on other sites

Yes I think session will do it.

 

You need this at the start of each script using the session:

 

<?php

 

session_start();

 

?>

 

This creates a persistent array called $_SESSION - note caps.

 

So, you would then use something like:

 

if (!isset($_SESSION['phone_image'])) {

  [work out your $image file name]

  $_SESSION['phone_image'] = $image;

}

 

You would then use $_SESSION['phone_image'] to referto your image file name whenever you need it.

 

You can also store any number of other variables in that array if you need to.

 

Hope this helps ...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.