How to write a login page?
Posted: Fri Jun 23, 2006 1:33 pm
How to create a login page which once authenticated takes the user to another page.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$authenticated = false; // Set authenticate default to false
$expected_username = "bob";
$expected_password = "1234!@#$";
if(!empty($_POST['username'])) $_SESSION['username'] = $_POST['username']; // Turn posted variables into session variables
if(!empty($_POST['password'])) $_SESSION['password'] = $_POST['password'];
if($_SESSION['username'] == $expected_username) && ($_SESSION['password'] == $expected_password){
$authenticated = true;
}Code: Select all
require('authenticate.php');
if($authenticated){
//Show page
}Code: Select all
<?php
$authenticated = false; // Set authenticate default to false
$expected_username = "admin";
$expected_password = "admin";
if(!empty($_POST['username'])) $_SESSION['username'] = $_POST['username']; // Turn posted variables into session variables
if(!empty($_POST['password'])) $_SESSION['password'] = $_POST['password'];
*if($_SESSION['username'] == $expected_username) && ($_SESSION['password'] == $expected_password)*
{
$authenticated = true;
}
?>
<table>
<tr>
<td>User</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="password"></td>
</tr>
</table>Code: Select all
Parse error: parse error in d:\program files\easyphp1-8\www\link\admin_login.php on line 11That should do itbluelad wrote:This is what i ahve doneBut it is showing this errorCode: Select all
<?php $authenticated = false; // Set authenticate default to false $expected_username = "admin"; $expected_password = "admin"; if(!empty($_POST['username'])) $_SESSION['username'] = $_POST['username']; // Turn posted variables into session variables if(!empty($_POST['password'])) $_SESSION['password'] = $_POST['password']; if(($_SESSION['username'] == $expected_username) && ($_SESSION['password'] == $expected_password)) { $authenticated = true; } ?> <table> <tr> <td>User</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password</td> <td><input type="text" name="password"></td> </tr> </table>The line in asteriks is line no 11Code: Select all
Parse error: parse error in d:\program files\easyphp1-8\www\link\admin_login.php on line 11
Code: Select all
require('authenticate.php');
if($authenticated){
//Show page
}You can use // for comments in php scripts... it was simply put there as an instruction. You put the page contents where //Show page is.bluelad wrote:One more query...if i want to access the particular page i should use this codeWhat does //show page mean over hereCode: Select all
require('authenticate.php'); if($authenticated){ //Show page }