plz help to create cookie on load page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
khalidhabib.cs
Forum Newbie
Posts: 14
Joined: Tue Jul 17, 2012 1:35 am

plz help to create cookie on load page

Post by khalidhabib.cs »

Code: Select all

$expire=time()+60*60*24*30;                            
$count=0;
				if(isset($_SESSION['counter'])){
				$num=$_SESSION['counter'];
				for($i=0;$i<$num+1;$i++){
				
					if(!empty($_POST)){
						//$arr=$_POST['p_name'.$i.''];
						//$_SESSION['p_name']=array_unique($arr);
						if(isset($_COOKIE['p_name'])||isset($_COOKIE['qty'])||isset($_COOKIE['prod_price'])){
						//setcookie("p_name[".$count."]",$_POST['p_name'.$i.''],$expire);
					}
						//$_SESSION['p_name'][$i];
				
					else {
						//$array[$i]=$_POST['p_name'.$i.''];
						 setcookie("p_name[".$count."]",$_POST['p_name'.$i.''],$expire);
						 setcookie("qty[".$count."]",$_POST['product_qty'.$i.''],$expire);
						 setcookie("prod_price[".$count."]",$_POST['prod_price'.$i.''],$expire);
					//setcookie("p_name[".$count."]",$_COOKIE['p_name'][$count],$expire);
				
						 } // end of else
						 
                  	 	 echo "</tr>";
					}// end if isset
					 $count++;
					 }// end of main for
				}
dear friends this my code to create cookie by posted values .problem is that it does not create cookie on page load ,it creates when i refresh the page ..what is problem in this code plz help
thanks in advance
Last edited by Benjamin on Fri Oct 19, 2012 1:23 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: plz help to create cookie on load page

Post by requinix »

Take a good, hard, long look at where you have {s and }s and fix your indentation to reflect the structure your code actually has. After doing that it should be much easier to see why it's not setting the cookies.
Post Reply