View previous topic :: View next topic |
Author |
Message |
Override -
Joined: 25 Nov 2003 Posts: 124 Location: Virtual Abyss N Area 61
|
Posted: Thu Mar 05, 2009 11:03 pm Post subject: PHP login |
|
|
can some one tell me what i am doing wrong with this code
config.php
Code: | <?php
$username = array('Admin', 'User');
$password = array('adminpass', 'userpass');
?> |
index.php
Code: | <?php
require ("config.php");
session_start();
if ((!$username) || (!$password))
{
echo '<form name=login method=post action="">
user:<input type=text name=user><br>
pass:<input type=text name=pass><br>
<input type=submit value=go>
</form>';
}
else
{
if($user==$username && $pass==$password)
{
session_register("username");
session_register("password");
echo "Congratulations &username, you have logged in!<br>
<a href=\"?logout=1\" >Logout</a>";
}
else
echo "Incorrect Password please <a href=?index.php?>try again</a>";
}
if($logout==1)
{
session_unregister("username");
session_unregister("password");
}
?> |
|
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Fri Mar 06, 2009 3:46 pm Post subject: |
|
|
You haven't told the form where to post to in action="" and also you didn't bring any sent variables into the script. action="" would be the php script the processing script will be in.
Use
Code: | if($_POST){ //if the form was posted, grab the variables
$variable = $_POST['inputname']; //$variable = variable name to use in the script, inputname = name of the input from the form.
}
else{
echo "Not posted properly";
} |
_________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Fri Mar 06, 2009 4:54 pm Post subject: |
|
|
I had a little fun with your concept. See http://code-bin.homedns.org/250
There are four files in the post.
Instructions
Place login.php, config.php, and verify.php all in the same folder on your server, preferably in the root web folder.
Use restricted.php as a template for any pages restricted to logged-in users. Make sure to change the paths in this script if this page winds up in another folder on your server or if you placed the 3 other files somewhere other than the root web folder. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
floridamary4 -
Joined: 30 Mar 2009 Posts: 8
|
Posted: Wed Apr 22, 2009 1:50 pm Post subject: re: |
|
|
thanks for your help :) |
|
Back to top |
|
|
scottlpool2003 -
Joined: 13 Sep 2008 Posts: 3
|
Posted: Fri May 15, 2009 12:21 pm Post subject: |
|
|
pkSML thanks for sharing that link. I don't use arrays personally, I store user details in a database but it's the same principle. Check that the user exists, if it does check the password else username/password is incorrect.
I've played around quite a bit with user registration/logins I looked for so many scripts but I never quite found exactly what I was looking for so I just wrote it myself, so much easier. Then I made a comment system, and as I became more advanced I added extra feats such as if they were male make their comment color blue, else make it pink. I've had much fun with PHP/SQL. _________________ Watch Free Movies - MySpace Unblock - Online Movies |
|
Back to top |
|
|
|