plz i have a login system , i want to make cookies inside it ,when the person login this is my code login.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="login2.php"> <label>username <input name="username" type="text" id="username" /> </label> <p> <label>password <input name="password" type="password" id="password" /> </label> </p> <p> <label> <input type="submit" name="Submit" value="Submit" /> </label> </p> </form> <p> </p> </body> </html> PHP: and login2.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <? $conn=mysql_connect("localhost","root","root"); mysql_select_db('project3'); include("include.php"); $username=$_POST['username']; $password=$_POST['password']; $password=md5($password); if ($username&&$password) { if (checklogin($username,$password)) { echo "success"; } else { echo "failed"; } } ?> </body> </html> PHP:
In the login2.php you have code before <?, which will not let the cookie headers be sent to browser. It is a standard that when you send anything as header to browser, there bust not be even a single byte already sent. PHP distribution for win32 might allow sometimes but not always. And please explain " i want to make cookies inside it ". regards
<? $conn=mysql_connect("localhost","root","root"); mysql_select_db('project3'); include("include.php"); $username=$_POST['username']; $password=$_POST['password']; $password=md5($password); if ($username&&$password) { if (checklogin($username,$password)) { setcookie("username", $username, time()+3600, "", ".domain.com"); setcookie("password", $password, time()+3600, "", ".domain.com"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php echo "success";} else { echo "failed"; } } ?> </body> </html> PHP: hope that helps but this is just of the top of my head and personally i would prefer to use sessions or use a customisable validation library