Title: PHP setcookie
Last modified: August 18, 2016

---

# PHP setcookie

 *  [Mark (podz)](https://wordpress.org/support/users/podz/)
 * (@podz)
 * [22 years ago](https://wordpress.org/support/topic/php-setcookie/)
 * I’m trying to use the ALA styleswitcher.
    I tested on my machine, but the cookie
   would not get written using PHP (a search here said that too) so I lobbed it 
   onto my site. Both of these fail to set a cookie. First is from the ALA article,
   second is from michel v who commented on it. I have no cookie restrictions in
   place, and js cookies can and are set. I know I could use the js file to do it,
   but this is just annoying me now 🙂 What am I doing wrong ? `<?php setcookie ('
   sitestyle', $set, time()+31536000, Â» '/', 'tamba2.org.uk/T2/', '0'); header("
   Location: $HTTP_REFERER"); ?> <?php $set = $_GET['set']; $set = preg_replace('#[
   ^a-zA-Z0-9_-]#', '', $set); setcookie ('sitestyle', $set, time()+31536000, '/','
   tamba2.org.uk/T2/', '0'); header('Location: '.$_SERVER['HTTP_REFERER']); ?>

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [TechGnome](https://wordpress.org/support/users/techgnome/)
 * (@techgnome)
 * [22 years ago](https://wordpress.org/support/topic/php-setcookie/#post-81870)
 * I’m going to take a wild stab here and say, could it be the difference between‘
   tamba2.org.uk/T2/’ and ‘www.tamba2.org.uk/T2/’ ??
    You didn’t have it on your
   site so I couldn’t see for sure if that’s the difference or not. I know I read
   about quite a few problems by people trying to get setcookies to work out on 
   the PHP.net site, and no one seemed to have any real answers. TG
 *  Thread Starter [Mark (podz)](https://wordpress.org/support/users/podz/)
 * (@podz)
 * [22 years ago](https://wordpress.org/support/topic/php-setcookie/#post-81876)
 * Ta..just tried that, still no joy.
    I know my switching thing is wrong, but until
   I can get a cookie set, I can’t really do the ‘trial and error’ until it works.
   Hmmm
 *  [mattread](https://wordpress.org/support/users/mattread/)
 * (@mattread)
 * [22 years ago](https://wordpress.org/support/topic/php-setcookie/#post-82138)
 * What about this:
    `setcookie ('sitestyle', $set, time()+31536000, '/T2/', '.tamba2.
   org.uk', '0');`

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP setcookie’ is closed to new replies.

 * 3 replies
 * 3 participants
 * Last reply from: [mattread](https://wordpress.org/support/users/mattread/)
 * Last activity: [22 years ago](https://wordpress.org/support/topic/php-setcookie/#post-82138)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
