mysql_real_escape_string($username) then storing as cookie and used to verify login
<p>So i have a page where i have stored the users username as a cookie and use it for different things. However i have hit a wall. If the username contains anything that is / when using <code>escape_string</code> things act up. I was able to get the username to be <code>echo</code>'ed correctly on one page however on another page i am not able to get it to come up properly. If i just echo the cookie on that page straight up i get / (the username im using is "" just to test). My server seems to auto escape variables sometimes so i am not 100% sure when it auto applies slashes and when it doesn't, as when i send out variables using php (sending out email with variable) they are escaped and when i save them to the database (sending variable to mysql) they are not slashed? So here is my code for everything i think might help, keep in mind the username in this case is "". </p>

<p>Registering the username:</p>

<pre><code> $username = mysql_real_escape_string($_POST['username']);
</code></pre>

<p>Setting up the cookie:</p>

<pre><code>$username = mysql_real_escape_string($_GET['username']);
$user = stripslashes($username);
setcookie('username', $user, time()+3600*24);
</code></pre>

<p>Working page:</p>

<pre><code>  if(isset($_COOKIE['username']))
   { 
  $login = '&lt;a id="popup_link_3" class="popup_link menu"&gt;&lt;span&gt;' . stripslashes($_COOKIE['username']) . '&lt;/span&gt;&lt;/a&gt;'; }
else{ 
 $login = '&lt;a  id="popup_link_2" class="popup_link menu"&gt;&lt;span&gt;Login&lt;/span&gt;&lt;/a&gt;';
 } 
</code></pre>

<p>here is where the username is echoed on the working page and i see "":</p>

<pre><code> &lt;? echo $content1 ?&gt;
 &lt;li&gt; &lt;? echo $login ?&gt;&lt;/li&gt;
 &lt;? echo $content2 ?&gt;
</code></pre>

<p>Non working page:</p>

<pre><code> $username = $_COOKIE["username"];
</code></pre>

<p>what i see when i echo <code>$username</code> is <code>/</code> and when i <code>stripslashes</code> i see nothing.</p>

<p>cookie value when viewed through firefox after being set:<code>%22%22</code></p>
