Page 1 of 1

[SOLVED]Cookie

Posted: Mon Aug 07, 2006 12:27 pm
by NiGHTFiRE
Hey,
I'm setting a cookie on the user that's logging in so next time he visits the site his username is saved in the box.
I'm trying to show the cookie by doing this:

Code: Select all

$login1 = "<form action=\"index.php\" method=\"post\"> 
        Användanamn:<br /> 
        <input name=\"username\" ";
$login1 .= "value="; 
$login1 .= $_COOKIE['Username']; 
$login1 .= "class=\"login_input\" type=\"text\"/><br /> 
        Lösenord:<br /> 
        <input class=\"login_input\" type=\"password\" name=\"password\" /><br /> 
        <input type=\"submit\" value=\"Logga in\" name=\"submit\"/> 
      </form> ";
But it doesn't work. the class=\"login_input\" gets in the value as well etc etc.
Thanks,
David

Posted: Mon Aug 07, 2006 12:35 pm
by feyd
Nothing is found in $_COOKIE['Username']. Since you haven't placed quotes round the value attribute, it's picking up the following text.

If you're expecting the cookie data to be there on the same page request where the cookie is set, you won't see it until the browser requests the page again. That is if the cookie set at all.

Posted: Mon Aug 07, 2006 12:38 pm
by volka
And there's no need for this string-concat-escape nightmare ;)
Try

Code: Select all

$login1 = '<form action="index.php" method="post">
		<div>
			Användanamn:
			<br />
			<input name="username" value="'.$_COOKIE['Username'].'" class="login_input" type="text"/>
			<br />
			Lösenord:
			<br />
			<input class="login_input" type="password" name="password" />
			<br />
			<input type="submit" value="Logga in" name="submit"/>
		</div>
	</form>';