SChaput
10-13-2008, 06:51 PM
I am trying to create a basic login form in php, (i do not have access to mysql tables). The username and password are predefined in the code below as 'admin' and 'password' and they are kept in globalvars.php. I want to try and make something where i can have multiple logons with their own respective password. maybe two dimensional array?
If possible id like the user to be able to 'make an account' and select a username and password and have it added to the array. Then be able to log into my site with that name.
If thats not possible, i'd like to be able to add someones username and password into an array and then allow them to user that information.
Any help is greatly appreciated.
<?php
/* Today is October 9, 2008, 9:55 pm */
$today = date("F j, Y, g:i a"); // October 9, 2008, 9:55 pm
?>
<?php
if (!isset($_POST['submit']))
{
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<table width="296" border="0" align="right">
<tr>
<td width="290"><strong>System Time</strong>: <?php echo $today;?></td>
</tr>
</table>
<p> </p>
<table width="255" align="center">
<tr>
<td width="310"><fieldset><legend>Login</legend>
<form action="<?$_SERVER['PHP_SELF']?>" method="post">
<div>
<p>Username:
<input type="text" name="username" />
<p>
Password:
<input type="password" name="password" />
<p>
<center> <input type="submit" name="submit" value="Login" /></center>
</div>
</form></fieldset></td>
</tr>
</table>
</body>
</html>
<?php
include 'globalvars.php';
}
else //otherwise, let's process this stuff
{
if($_POST['username'] == "$username" && $_POST['password'] == "password") //if they got it right, let's go on
{
session_start();
session_register("mysessionvariable"); //set a variable for use later
$id = session_id(); //let's grab the session ID for those who don't have cookies
$url = "Location: index.php?sid=" . $id;
header($url);
}
else //they got something wrong and we should tell them
{
?>
<html>
<head>
<title>My Login Form</title>
</head>
<body>
<span style="color:#ff0000;">Password/Username Is Invalid</span><br />
<form action="<?$PHP_SELF?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>
<?php
}
}
?>
If possible id like the user to be able to 'make an account' and select a username and password and have it added to the array. Then be able to log into my site with that name.
If thats not possible, i'd like to be able to add someones username and password into an array and then allow them to user that information.
Any help is greatly appreciated.
<?php
/* Today is October 9, 2008, 9:55 pm */
$today = date("F j, Y, g:i a"); // October 9, 2008, 9:55 pm
?>
<?php
if (!isset($_POST['submit']))
{
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<table width="296" border="0" align="right">
<tr>
<td width="290"><strong>System Time</strong>: <?php echo $today;?></td>
</tr>
</table>
<p> </p>
<table width="255" align="center">
<tr>
<td width="310"><fieldset><legend>Login</legend>
<form action="<?$_SERVER['PHP_SELF']?>" method="post">
<div>
<p>Username:
<input type="text" name="username" />
<p>
Password:
<input type="password" name="password" />
<p>
<center> <input type="submit" name="submit" value="Login" /></center>
</div>
</form></fieldset></td>
</tr>
</table>
</body>
</html>
<?php
include 'globalvars.php';
}
else //otherwise, let's process this stuff
{
if($_POST['username'] == "$username" && $_POST['password'] == "password") //if they got it right, let's go on
{
session_start();
session_register("mysessionvariable"); //set a variable for use later
$id = session_id(); //let's grab the session ID for those who don't have cookies
$url = "Location: index.php?sid=" . $id;
header($url);
}
else //they got something wrong and we should tell them
{
?>
<html>
<head>
<title>My Login Form</title>
</head>
<body>
<span style="color:#ff0000;">Password/Username Is Invalid</span><br />
<form action="<?$PHP_SELF?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>
<?php
}
}
?>