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

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.