[SOLVED]Cookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

[SOLVED]Cookie

Post 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
Last edited by NiGHTFiRE on Mon Aug 07, 2006 1:38 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>';
Post Reply