www.webdeveloper.com
Results 1 to 2 of 2

Thread: please help for cookie

  1. #1
    Join Date
    Aug 2012
    Posts
    5

    please help for cookie

    $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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,918
    If by "not create cookie" you mean it is not in $_COOKIE, that would be correct. setcookie() only sends a HTTP cookie header to the client, it does not touch the $_COOKIE array. $_COOKIE only gets populated (automatically) when it receives a corresponding HTTP cookie request from the browser when it requests a URI. If you want $_COOKIE to be populated at the same time that you set the cookie header (via setcookie()) in a script, then you'll need to explicitly set it in the $_COOKIE array at that time.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles