enaceo
05-20-2008, 07:39 PM
Hi there .
I have a problem getting this code to work - it's a login page i'm making for a site - but for some reason it's not wroking .
<?php
require_once("functions.php");
connection("localhost","abcd","%","logintest");
if(isset($_POST['submit'])) {$user=$_POST['user'];
$passw=$_POST['passw'];
if(authorization($user,$passw)) {
echo "<center><h3><b>".$user."<br />Name and password OK . Access approved!</b></h3>
<a href=\"sectionA.php\">Section A</a> | "."<a href=\"sectionB.php\">Section B</a> | ".
"<a href=\"logout.php\">Logout</a></center>";
}
else { echo "<center><hr>".$_POST['user']."<br />NAME OR PASS WRONG ACCESS DENIED!</hr></center>
<center><a href='".$_SERVER['PHP_SELF']."'>Back</a>";
}
}
else {
?>
<center><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" >
<table>
<tr>
<td>Username</td><td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password(case sensitive):</td>
<td><input type="password" name="passw" /></td>
</tr>
<tr>
<td><input type="reset" value="Reset values" /></td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
</center>
<?php
}
?>
This is the login page - if the form has not been submitted then it should displaya login form , which it does .When the submit button is pressed , the page should reload and display the links .However , it does not ... it reloads and it displays the form again .After some personal debugging attemps , I foudn out that the problem is the if(isset($_POST['submit'])) part .If I insert an $aux or something equal to one there the page reloads but like this it does not work ...
Also , here is the code for the functions I used :
<?php
session_start();
header("Cache-control: private");
function connection($host,$user,$passw,$db) {
$conn=mysql_connect($host,$user,$passw) or
die("Cannot establish connection");
mysql_select_db($db,$conn) or die("Cannot access database");
}
function authorization($user,$passw) {
$passw=md5($passw);
$rez=mysql_query("SELECT username,password FROM users WHERE username='$user' AND password='$passw'");
if(mysql_num_rows($rez)==1) {
session_start();
$_SESSION['user']=$user;
$_SESSION['passw']=$passw;
$_SESSION['id']=session_id();
return true;
}
else return false;
}
function authenthification() {
if($_SESSION['id']!=session_id()) {return false;}
else { $rez=mysql_query("SELECT username,password FROM users WHERE username='".$_SESSION['user']."' AND password='".$_SESSION['passw']."'");
if(mysql_num_rows($rez)!=1)
return false;
else
return true;
}
}
?>
I'd be really grateful is somebody could tell me what the problem is ...
I'm using PHP 5.2.5 MySQL server 5 on Apache 2.2 .
I have a problem getting this code to work - it's a login page i'm making for a site - but for some reason it's not wroking .
<?php
require_once("functions.php");
connection("localhost","abcd","%","logintest");
if(isset($_POST['submit'])) {$user=$_POST['user'];
$passw=$_POST['passw'];
if(authorization($user,$passw)) {
echo "<center><h3><b>".$user."<br />Name and password OK . Access approved!</b></h3>
<a href=\"sectionA.php\">Section A</a> | "."<a href=\"sectionB.php\">Section B</a> | ".
"<a href=\"logout.php\">Logout</a></center>";
}
else { echo "<center><hr>".$_POST['user']."<br />NAME OR PASS WRONG ACCESS DENIED!</hr></center>
<center><a href='".$_SERVER['PHP_SELF']."'>Back</a>";
}
}
else {
?>
<center><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" >
<table>
<tr>
<td>Username</td><td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password(case sensitive):</td>
<td><input type="password" name="passw" /></td>
</tr>
<tr>
<td><input type="reset" value="Reset values" /></td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
</center>
<?php
}
?>
This is the login page - if the form has not been submitted then it should displaya login form , which it does .When the submit button is pressed , the page should reload and display the links .However , it does not ... it reloads and it displays the form again .After some personal debugging attemps , I foudn out that the problem is the if(isset($_POST['submit'])) part .If I insert an $aux or something equal to one there the page reloads but like this it does not work ...
Also , here is the code for the functions I used :
<?php
session_start();
header("Cache-control: private");
function connection($host,$user,$passw,$db) {
$conn=mysql_connect($host,$user,$passw) or
die("Cannot establish connection");
mysql_select_db($db,$conn) or die("Cannot access database");
}
function authorization($user,$passw) {
$passw=md5($passw);
$rez=mysql_query("SELECT username,password FROM users WHERE username='$user' AND password='$passw'");
if(mysql_num_rows($rez)==1) {
session_start();
$_SESSION['user']=$user;
$_SESSION['passw']=$passw;
$_SESSION['id']=session_id();
return true;
}
else return false;
}
function authenthification() {
if($_SESSION['id']!=session_id()) {return false;}
else { $rez=mysql_query("SELECT username,password FROM users WHERE username='".$_SESSION['user']."' AND password='".$_SESSION['passw']."'");
if(mysql_num_rows($rez)!=1)
return false;
else
return true;
}
}
?>
I'd be really grateful is somebody could tell me what the problem is ...
I'm using PHP 5.2.5 MySQL server 5 on Apache 2.2 .