Jump to content

setting a variable if a session or cookie isset


merylvingien

Recommended Posts

Hi girls and boys

 

I am trying to set a variable if a session OR a cookie has been set, but am unsure on how to write the statement...

 

if (isset($_SESSION['name'])||isset($_COOKIE['name'])) {$variable = $_SESSION['name']||$_COOKIE['name'];}

 

Obviously not working there, but just need a pointer here.

any help is appreciated...

Link to comment
Share on other sites

Thanks for the reply, but i tried this but wont work unless the cookie is set.

I have only ever worked with either cookies or sessions, never both!

 

Seems impossible to get both to work together smoothly.

 

Also for some reason, when i add this code to the top of the image upload file, it breaks the code, everything stops working correctly....

 

Headache!!!!

Link to comment
Share on other sites

Thanks for the reply, but i tried this but wont work unless the cookie is set.

I have only ever worked with either cookies or sessions, never both!

 

Seems impossible to get both to work together smoothly.

 

Also for some reason, when i add this code to the top of the image upload file, it breaks the code, everything stops working correctly....

 

Headache!!!!

What Pikachu gave you will work exactly right, you may not be printing the right variables.  Right before this IF check, do:

var_dump($_COOKIE);var_dump($_SESSION);

See what comes out.  I bet the variables aren't set the way you think they are.

 

To be clear, what we think you're saying is:  "I want $variable to be the value of EITHER $_COOKIE['name'] OR $_SESSION['name'}, whichever is set.  If both are set, use the $_COOKIE variable."  If that's not what you mean, rephrase the question.

 

-Dan

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.