Jump to content

PHP Cookie Issue, URL Address As Name Not Working?


DrRobot

Recommended Posts

Hello,

 

I'm having an issue with using a php variable (of the current page url) as a cookies name. Here's an example of what I'm trying to do:

 

$directory = "/main/index.php?id=7";
$cName = "path_".$directory;
if(isset($_COOKIE[$cName])){
   echo "Do something NOW!!!";
   setcookie($cName, '1', mktime(23,59,59));
}

 

echoing the isset check doesn't return anything, no 0, no 1.

 

I can print_r $_COOKIE; and it shows the cookie exists, I just can't check if it exists with what I'm doing here.

 

From what I've learned is that the cookie name is something like: "testing" it works just fine, but if it's that $cName variable it doesn't work.

 

Any ideas?

Link to comment
Share on other sites

If you were developing with error reporting enabled, which you should be, you'd see a warning similar to: Warning: Cookie names can not contain any of the following '=,; \t\r\n\013\014' . . .

I guess this is probably the reason that the $_COOKIE[$cName] isn't working.

 

Also, I have error_reporting(E_ALL); at the top of my file, I guess it's not working? BTW, I'm using WAMP.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.