Jump to content

Settings A Cookie


morrisjohnny
 Share

Recommended Posts

I'm trying to create a shopping cart for www.SweetMemoriesOnline.co.uk as i'm redesigning their website (The Payment will still be managed By Paypal)Here's my attempt of setting a cookie

<?phpif(isset($_COOKIE['smshoppingcart'])){	setcookie("smchoppingcart",$_COOKIE['smshoppingcart'],time()+3600);	mysql_query("UPDATE $tbl_cookies SET LU=(time()+3600)");}else{	$value=mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9).mt_rand(5, 9);	$cookiedb=mysql_query("SELECT * FROM $tbl_cookies WHERE ref='$value'");	if(mysql_num_rows($cookiedb)==0)	{		setcookie("smchoppingcart",$value,time()+3600);		mysql_query("INSERT INTO $tbl_cookies (ref,LU)VALUES('$value','time()+3600')");	}	else	{		include"auto_cookie.php";	}}echo mysql_error();echo $value;echo '<br /><br />z|'.$_COOKIE['smshoppingcart'].'|z<br /><br />';?>

This is called by shoppingcart.phpa-track of their basket. I was going to use their IP but if they become disconnect and reconnect chances are a new ip may be in order.

<?phpinclude"auto_cookie.php";....

index.php (the only viewable page)

<?phpinclude"Settings/__connect__.php";$db=mysql_connect($sql_host, $sql_user, $sql_password);mysql_select_db($sql_database, $db);include"shoppingcart.php";

Anyone interested in comments i've included a quick screenshotScreenshot

Link to comment
Share on other sites

setcookie("smchoppingcart",$value,time()+3600);You are setting smchoppingcart in two places in both the if and else. You might want to change smchoppingcart to smshoppingcart.
Cheers, i copied and pasted the values but type it wrong in the first statment :) lol Newbie mistake, Sorry, Working fine now :) Cheers Mate :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...