Hi, OK, so here's what I want to do: I have a website with several different products for sale on it. I promote the site using PPC. I want to be able to run one PPC ad campaign for the site with normal pricing (let's say each product is $200), and another campaign for the site with sale pricing (sale price of each item is $100). I want to be able to put a cookie on the users computer when they click on the PPC ads for the sale price it displays the sale prices instead of the normal prices. This should be fairly simple, right? I know a little PHP and am good with HTML, as I understand it is should function sort of like this: User clicks on ad for sale price, gets directed to landing page that puts cookie on their computer. User browses website, wherever there is mention of a price the site checks to see if the user has the cookie, if they do the sale price is shown, if not then the regular price is shown. Does anyone know of a simple tutorial that would show how to do this? I found a bunch of tutorials showing how to set up the cookie, but none that showed how to get the page to display different messages (prices) based on the cookie being present or not. If anyone can help I would really appreciate it! Thanks, George
page making cookie on user's computer: setcookie("bonus", "lower_price"); The page where price is shown: You can buy it for <?php if ($HTTP_COOKIE_VARS["bonus"]) echo "100$";else echo "200$"; ?>
You don't actually need brackets on if statement in PHP if the statement is only one line. You only need them if it's more than one line. Saves a bit of time when writing code so it's useful. Sky22
I would suggest using sessions rather than cookies , some people have restrictive cookie settings. If you are using PHP on ur site then it shouldnt be a problem. on top of each page OR in ur top level include file session_start(); if(user is coming from PPC){ $_SESSION['PPC'] = 1; } to check if($_SESSION['PPC'] == 1){ echo "Price : 100"; }else{ echo "Price : 200"; }
Yes, but at least he got rid of the deprecated HTTP_*_VARS Also, when using one line conditionals, either use the ternary operating or brackets like Meth done to improve readability. I prefer: echo ($_SESSION['bonus'] ? '$100' : '$200'); Code (markup): Note the session used (just realised sabmalik already covered this )
Let me see how you guys are getting good looking code session_start(); if(user is coming from PPC){ $_SESSION['PPC'] = 1; } ///to check if($_SESSION['PPC'] == 1){ echo "Price : 100"; }else{ echo "Price : 200"; } Code (markup):