Necrohhh
Necrohhh

Reputation: 223

PHP - Allow Users To Set A Cookie

I'd like to allow users to set a variable through a text form, $name for example, then I'd like to set a cookie after they fill the form, so the cookie is set to $name.

So if in the text form, the user set $name = 'John';

Then I'd like the cookie to be set to setcookie ("name", "John");

Thanks!

Upvotes: 0

Views: 67

Answers (2)

Tarun
Tarun

Reputation: 3165

    $name  = $_REQUEST['name'];  
   if(!isset($_COOKIE['name']))    
   {
    setcookie('name',$name,0);//The cookie will expire at the end of the session 
   }

Upvotes: 0

Christoph
Christoph

Reputation: 11

The following code

setcookie('name',$_GET['name']); 

should do it.

Upvotes: 1

Related Questions