title: Unable to set Cookie in php
body: <p>I am working with social login.  I tried <a href="http://www.vignesh.gvignesh.org/oauthreg/reg.html" rel="nofollow">login with facebook</a>.  Once the user is authenticated I can get their value and I need to set their id in a cookie so that I can create a session across the site. </p>
  
  <p>Here is my code,</p>
  
  <pre><code>&lt;?php
  /*
   * login_with_facebook.php
   *
   * @(#) $Id: login_with_facebook.php,v 1.2 2012/10/05 09:22:40 mlemos Exp $
   *
   */
      require('http.php');
      require('oauth_client.php');
  
      $client = new oauth_client_class;
      $client-&gt;server = 'Facebook';
      $client-&gt;redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].
          dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/login_with_facebook.php';
  
      $client-&gt;client_id = ''; $application_line = __LINE__;
      $client-&gt;client_secret = '';
  
      if(strlen($client-&gt;client_id) == 0
      || strlen($client-&gt;client_secret) == 0)
          die('Please go to Facebook Apps page https://developers.facebook.com/apps , '.
              'create an application, and in the line '.$application_line.
              ' set the client_id to App ID/API Key and client_secret with App Secret');
  
      /* API permissions
       */
      $client-&gt;scope = 'email';
      if(($success = $client-&gt;Initialize()))
      {
          if(($success = $client-&gt;Process()))
          {
              if(strlen($client-&gt;access_token))
              {
                  $success = $client-&gt;CallAPI(
                      'https://graph.facebook.com/me', 
                      'GET', array(), array('FailOnAccessError'=&gt;true), $user);
              }
          }
          $success = $client-&gt;Finalize($success);
      }
      if($client-&gt;exit)
          exit;
      if($success)
      {
  ?&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Facebook OAuth client results&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  
  echo "This is id i got from facebook ".$user-&gt;id." I am unable to set this value in cookie.";
  
  mysql_connect('localhost', 'user_id', 'pwd');
  mysql_select_db("DB Name");     
  
  $sql    =   "INSERT INTO oauth SET auth_id  = ".$user-&gt;id.",
                                     name     = '".$user-&gt;name."',
                                     email    = '".$user-&gt;email."',
                                     link     = '".$user-&gt;link."'";
  mysql_query($sql);
  
  if(isset($_COOKIE['auth_id']))
      unset($_COOKIE['auth_id']);
  
  setcookie("auth_id", $user-&gt;id, time()+60*60*24, "/");
  ?&gt;
  
  &lt;script&gt;
  //window.close();
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
      }
      else
      {
  ?&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;OAuth client error&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;OAuth client error&lt;/h1&gt;
  &lt;pre&gt;Error: &lt;?php echo HtmlSpecialChars($client-&gt;error); ?&gt;&lt;/pre&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
      }
  ?&gt;
  </code></pre>
  
  <p>Just setting the cookie after updating my domain.  But this is not working for me.</p>