Tuesday 15 June 2010

moving user to another page by entering correct password using php -



moving user to another page by entering correct password using php -

i have log in page. want when user enters right username , password the page want open him. , if password , username wasn't right receive error in current page. , problem when open page first, have php undefined index error.

<form action="<?php echo $_server["php_self"]?>" method="post"> <div class="data"> <label for="name">username: </label> <input type="text" name="username"/> </div> <div class="data"> <label for="name">password: </label> <input type="password" name="password"/> </div> <input type="submit" value="log in" name="submit" id="submit"/> <?php $dbusername = "alex"; $dbpassword = "1234"; $username = $_post["username"]; $password = $_post["password"]; if($username = $dbusername&&$password = $dbpassword){ //the code moves user page. }else echo "please come in right username , password"; ?> </form>

thanks.

you have move php code origin of file serverside (which right thing do) avoid errors output before setting headers. additionally, status assigning variable values (=) instead of comparing values (==).

an (untested) illustration of setup work:

<?php $dbusername = "alex"; $dbpassword = "1234"; if(isset($_post['username'])) { $username = $_post["username"]; $password = $_post["password"]; if($username == $dbusername && $password == $dbpassword) { header("location: http://example.com/the/page/where/your/user/should/end/up"); exit; } else { $error = true; } } ?> <form action="<?php echo $_server["php_self"]?>" method="post"> <div class="data"> <label for="name">username: </label> <input type="text" name="username"/> </div> <div class="data"> <label for="name">password: </label> <input type="password" name="password"/> </div> <input type="submit" value="log in" name="submit" id="submit"/> </form> <?php if(isset($error)): ?> please come in right username , password <?php endif; ?>

php

No comments:

Post a Comment