Hello Man! , listen .. i started to learn PHP 4 days ago.. Now I am learn how to use in cookie. but I have a problem. After logging in I appears to me, "You are logged in" .. If I do "refresh" still appears to me .. But if I click on the "Home" is the login name .. So it disappeared for me <?php $user = $_POST["username"]; setcookie("youlog" , $user , time()+3600); /* =================================================================================== START ================================================================================ */ ini_set('display_errors', 0); $link = mysql_connect("localhost","root","")or die(mysql_error()); mysql_select_db('new')or die(mysql_error()); if($_POST["submit"]) { $user = $_POST["username"]; $pass = $_POST["password"]; $query = mysql_query("SELECT * FROM `register` WHERE username='".$user."' AND password='".$pass."'"); $res = mysql_num_rows($query); if ($res == 1) { echo '<div class="login">' . "." . $user . " " . 'התחברת בהצלחה</div>'; $cookie = $_COOKIE["user"]; echo '<div class=cookie>' . $_COOKIE["youlog"] . " " . '×תה מחובר' . '</div>'; } else { echo "<div class=login>!×©× ×”×ž×©×ª×ž×© ×ו ×”×¡×™×¡×ž× ××™× × × ×›×•× ×™×</div>"; } } /* =================================================================================== END ================================================================================ */ ?> <HTML> <HEAD> <TITLE> TheWall - × ×¡×• לגלות מה מסתתר מ×חורי החומה </TITLE> <style> input.user { position:absolute; top:120px; left:480px; border-width:0px; }; input.pass { position:absolute; top:176px; left:480px; border-width:0px; }; input.submit { position:absolute; top:210px; left:535px; }; div.log { font-family:arial; position:absolute; left:400px; top:250px; }; div.login { font-family:arial; position:absolute; left:420px; top:250px; font-size:12px; }; div.cookie { font-family:arial; position:absolute; left:780px; top:44px; font-size:12px; }; </style> </HEAD> <body> <img src="photos/test.jpg" width="1000" height="1000" border="0" alt="ר×שי" usemap="#web_Map"> <map name="web_Map"> <area shape="rect" alt="קישורי×" coords="85,362,118,400" href="links.php"> <area shape="rect" alt="×לופי×" coords="131,329,164,357" href="champ.php"> <area shape="rect" alt="צור קשר" coords="176,300,216,329" href="conract.php"> <area shape="rect" alt="הור×ות" coords="238,287,274,309" href="howtoplay.php"> <area shape="rect" alt="×ª×§× ×•×Ÿ" coords="297,292,327,300" href="rules.php"> <area shape="rect" alt="פרסי×" coords="342,292,374,309" href="prrizes.php"> <area shape="rect" alt="ר×שי" coords="393,300,422,321" href="index.php"> </map> <FORM METHOD=POST ACTION="index.php"> <INPUT class="user" TYPE="text" NAME="username"> <INPUT class="pass" TYPE="password" NAME="password"> <input type="submit" class="submit" value="התחבר" style="width:50px; height:23px; border:#ffffff 0px solid; font: bold 11px arial middle; background-color:c5df1e; color:white" name="submit" /> </FORM> <?php ?> </BODY> </HTML PHP:
You are using html input not using the value. You have to add some more code in your home page, like if(!empty($cookie)) { echo name } else { <FORM METHOD=POST ACTION="./"> <INPUT class="user" TYPE="text" NAME="username"> <INPUT class="pass" TYPE="password" NAME="password"> <input type="submit" class="submit" value="התחבר" style="width:50px; height:23px; border:#ffffff 0px solid; font: bold 11px arial middle; background-color:c5df1e; color:white" name="submit" /> </FORM> } PHP: I think you understand what i mentioned above.
Don't use just cookies for logging people in, that's very insecure since cookies are stored clientside and can be easily edited. Instead, use sessions.