ngecoding.com logo

Create cookie Across Subdomains in PHP

//if(youLikeIt || itHelpsYou)clickShare();

This code show you how to create a cookie in PHP.

<?php
    setcookie("name","value",time()+3600*24);
?>

The cookie created with name name and value value and expire in 1 day.

If you create cookie in  http://www.example.com/home/page.php, browser only transmitting the cookie to  www.example.com domain with /home path. 

 

If you want to create cookie that transmitted to all paths.

<?php
  setcookie("name","value",time()+3600*24,"/");
?>

The above code will create multipath cookie for your domain.

 

If you want to create cookie that accross subdomains., use this :

<?php
    setcookie("name","value",time()+3600*24,"/",".example.com");
?>

The above code will create multipath and multisubdomain cookie for your domain.

 

//if(youLikeIt || itHelpsYou)clickShare();
//Advertisements
Take a Break //non-technical articles
Hot Topics //most used tags
Email Subscriptions //We won't spam you. Honest!

Enter your email address:

Delivered by FeedBurner