Results 1 to 3 of 3

Thread: Problem setting PHP cookies on localhost

  1. #1
    Join Date
    Dec 2007
    Location
    UK
    Beans
    571
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Problem setting PHP cookies on localhost

    I have been trying for ages now and I cant seem to get cookies set via php on the localhost. THis is the code I'm using to set the cookie:
    Code:
    	function CarCookie($row, $num)
    	{
    		
    		$name ="car_1";
    		$str = "blah";
    		setcookie("car_1", "blah", false, "/", false);
    	}
    At the end of the page I call this function to print out the cookie:
    Code:
    	function Printout()
    	{
    		 echo "cookie:";
    		 print_r($_COOKIE);
    	}
    But nothing is ever set o_0 Can anyone say why this is?

  2. #2
    Join Date
    Sep 2007
    Location
    Rivendell
    Beans
    487
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Problem setting PHP cookies on localhost

    First off, enable error_reporting by putting

    Code:
    error_reporting(E_ALL);
    at the first line of any script. Some retard decided to deactivate error reporting by default in PHP 5.

    As for the cookie, I am not sure PHP will let you get away with providing "false" where you should provide a timestamp.

    Try a more basic form like this:
    Code:
    setcookie('car_1','blah');
    Also, you are actually making the necessary function calls and your browser is not set to automatically decline all cookies, right?
    True warriors don't follow paths - they make them.
    It's not their desire, it's their nature.

  3. #3
    Join Date
    Dec 2007
    Location
    UK
    Beans
    571
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Problem setting PHP cookies on localhost

    Cheers for the error reporting bit; I'll use that in future. Apparently the setcookie function needed those extra parameters when running via the localhost/loopback according to what I had read. I had originally tried it w/o them. Edit: Oh and according to the manual if theres no timestamp the cookies die when the browser is closed.

    I never got the cookies working, but managed to transfer the MySQL data to Javascript by writing Javascript code with PHP. So, my problems is solved; or at least until I need to use cookies again.

Tags for this Thread

Bookmarks

Posting Permissions

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