PHP - Can't create cookies -


i'm beginner php programmer, , can't set cookies.

i keep getting error:

notice: undefined index: user in d:\xampp\htdocs\bank\verify.php on line 28

notice: undefined index: pass in d:\xampp\htdocs\bank\verify.php on line 28

in code, i'm setting cookie value of $_post['user'] , $_post['pass'] form , printing out, won't work.

setcookie("user",$_post['user'],3600); setcookie("pass",$_post['pass'],3600); echo $_cookie["user"] . " " . $_cookie["pass"];  // line 28 

and here's form:

<form action="verify.php" method="post">     username: <input name="user" /><br />     password: <input name="pass" type="password" /><br />     <input type="submit" value="submit" /> </form> 

anybody know why happens? please help.

thanks.

cookies used next time visit page. there 3 general solutions: 1. save cookie , first time, echo post variables instead of cookie. code this:

setcookie('user', $_post['user'], time()+3600); // notice time() function setcookie('pass', $_post['pass'], time()+3600); // cant use absolute value here  if (!isset($_cookie['user'])) echo $_post['user'] . ' ' . $_post['pass'];     else echo $_cookie['user'] . ' ' . $_cookie['pass']; 

, if want store password in cookie (very bad idea), @ least hash it. code hashing this:

setcookie('pass', hash(whirlpool/*algorithm*/, $_post['pass']/*text*/), time()+3600); 

, when check password, hash , compare hashes.


2. solution session, work until close browser, whole session erased.
3. , best solution store user+password in mysql database or in .txt file on server side. still, don't forget hash it, because in database, can steal these informations using hack. if think, web secure - better safe sorry.
thats solution. quick note: if want store passwords important, hash it, prefarably use salted hash. try google it, there many articles hashing on internet.look @ site: http://php.net/manual/en/faq.passwords.php


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -