rhouk Posted February 1, 2008 Share Posted February 1, 2008 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!! Quote Link to comment https://forums.phpfreaks.com/topic/88935-cookies-or-session/ Share on other sites More sharing options...
nickdrums Posted February 1, 2008 Share Posted February 1, 2008 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/88935-cookies-or-session/#findComment-455595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.