Jump to content

Problem with cookies. Need to encompass all domains


morphboy23

Recommended Posts

Ok so I'm setting up a cookie for whenever a user logs into my site. Here's what I have:

 

setcookie('bloowoologinemail', $result['email'], time()+259200, '/', '.bloowoo.com');

 

Now, I thought that since I have '.bloowoo.com' for the domain, this cookie would be loaded at both http://www.bloowoo.com and http://bloowoo.com  yet it's not.

How can I fix it so that it's the same cookie for both with and without www?

Link to comment
Share on other sites

This doesn't answer your question, but it may solve your problem.  One option is to redirect all requests that hit bloowoo.com to hit www.bloowoo.com instead.  Then you don't need to worry about supporting two possible hostnames anywhere in your code.

Link to comment
Share on other sites

You can do this at the top of every script (this can be included in a global configuration file)

 

if ($_SERVER['HTTP_HOST'] === 'bloowoo.com') {
  $new_url = str_replace('bloowoo.com', 'www.bloowoo.com', $_SERVER['SCRIPT_URI']);
  header('Location: ' . $new_url);
  exit(0);
}

 

Hopefully that'll work.  Different servers sometimes set different variables in $_SERVER, so you might need to adjust it.

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.