Click to See Complete Forum and Search --> : Begginers Login help
Jamie_Garland
Dec 4th, 2008, 10:04 AM
Hi guys,
Below is the code but when i run the script on my server it shows the Access Denied before i even type anything in also when i type in the correct username and password how do i get it to remove the login box stuff and just leave the Access Granted text?.
<html>
<head/>
<body>
<form action="login.php" method=POST>
Username <input type=text name=user><br/>
Password <input type=text name=pass><br/>
<input type=submit value="Go"><p>
</form>
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
if (($user=='admin') && ($pass=='admin')) echo "Access Granted!";
else echo "Access Denied!";
?>
</body>
</html>
kfcSmitty
Dec 4th, 2008, 10:17 AM
I'm not going to give you the answer on this one, but I will attempt to help.
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
if (($user=='admin') && ($pass=='admin')) echo "Access Granted!";
else echo "Access Denied!";
?>
The above code is getting the post variables "user" and "pass" and putting them in the local variables $user and $pass.
So, when you first access the form, you have not posted anything, thus the "Access Denied" message.
If you enter "admin" and "admin" into the text boxes, it will post back and show "Access Granted" but the form will still appear.
You will need to check your variables and decide what you want to display based on that.
Lukeidiot
Dec 5th, 2008, 08:05 AM
Hi guys,
Below is the code but when i run the script on my server it shows the Access Denied before i even type anything in also when i type in the correct username and password how do i get it to remove the login box stuff and just leave the Access Granted text?.
<html>
<head/>
<body>
<form action="login.php" method=POST>
Username <input type=text name=user><br/>
Password <input type=text name=pass><br/>
<input type=submit value="Go"><p>
</form>
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
if (($user=='admin') && ($pass=='admin')) echo "Access Granted!";
else echo "Access Denied!";
?>
</body>
</html>
Unless "login.php" is the same page, then it is not processing the infomation in the text boxes.
Alternatively, try
<form action="" method=POST>
Jamie_Garland
Dec 5th, 2008, 12:36 PM
Can anyone help me with placing a link if the access has been accepted and if its denied the link dosent show this is the code that i have so far?.
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
if (($user=='admin') && ($pass=='admin')) echo "Access Granted!";
else echo "Access Denied!";
?>
kfcSmitty
Dec 5th, 2008, 01:34 PM
That code looks identical to the code you posted above.
At least change your echo to output a link before you ask for help; You'll find most people around here help those who help themselves.
Also, if you're looking at having someone authenticate to get into your page, and any subsequent pages, you should look into Sessions.
W3Schools has a good tutorial at:
http://www.w3schools.com/php/php_sessions.asp
But I would also suggest you go through their entire PHP tutorial at:
http://www.w3schools.com/php/php_intro.asp
Jmacp
Dec 12th, 2008, 03:29 AM
Check to see if the POST is == ""
If(!$_POST['user'] == "" && !$_POST['pass'] == ""){
if (($user=='admin') && ($pass=='admin')) echo "Access Granted!";
else echo "Access Denied!";
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.