Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Help for cookie

  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help for cookie

    PHP Code:
    $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 Inigoesdr; 10-20-2012 at 06:34 AM.

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    74
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Hi

    This is correct, when you set a cookie you need a page refresh for it to become visiable.

    You could send the user to a redirect page, so it would redirect the user back to the page they were originally where the cookie was set.

    Hope this helps. If you need any more info checkout the php manual.

    http://php.net/manual/en/function.setcookie.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •