Jump to content

Users cannot login my website


Xenia

Recommended Posts

Hi everyone,I have a problem with the login of the users.The first page of my website have a form where the user has to write his/her username and password(loginform.php). When the user clicks the submit button the user is being redirected to the page where the user being authenticated(password_input.php). The user might be either administrator or regular user.If the administrator logins the pages will include a specific navigation menu(logoffheaderAdmin.php).if a regular user logins then another navigation menu appears(logoffheader.php). In order the system to know which menu to display will check with the page check_login.php. The problem now is that the user cannot login.When the user enters the correct details it just appears a blank page.if the user enters wrong details it just display that "Your password is not correct. Please log on again!".I think that the problem might be in the "password_input.php" page and specially with the "header()" function. The strange thing is that if i put the correct details and click submit the blank page will appear but if i add in the url the address "http://www.domain.com/Staff/check_login.php" and manually redirect, it displays the correct menu. I will display the code that i have written and i would realy appreciate any help and suggestions.This is the code from the page "loginform.php"

<?      session_start();   if($_SESSION['username']){          echo $username.". You have logged on!";        require($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php');         }else{   ?><form action="password_input.php" method="POST" name = "login"><table align="center" bgcolor="#FFCC66">    <tr>           <td align="center" colspan="2">Log On</td>        </tr>        <tr>           <td>Username:</td>       <td><input type="text" name="uname"></td>        </tr>        <tr>           <td>Password:</td>       <td><input type="password" name="passwd"></td>    </tr>        <tr>           <td></td>           <td><input type="submit" value="Log in" name="submit"><input type="reset" value="Reset" name="reset"></td>        </tr></table></form><? }?>

This is the code for the page "password_input"

<?   session_start();   include "dbconnect.php";   if(empty($_POST['uname'])||empty($_POST['passwd'])){                   include("loginform.php");                    exit;   }    $uname= $_POST['uname'];    $query = "SELECT * FROM Webusers WHERE username='$uname'";    $result = mysql_query($query);    $row = mysql_fetch_array($result);    $encrypted_password = md5($_POST['passwd']);    if($encrypted_password!=$row['password']){         echo "<h3>Your password is not correct. Please log on again!</h3>";         include("loginform.php");    }else{                 $_SESSION['username']=$uname;         $_SESSION['isAdmin']=$row['admin']=='yes';         header("Location:http://www.domain.com/Staff/check_login.php");    }//var_dump($_SESSION);?>

This is the code for page "check_login.php"

 <?                                                                                                                                                                                                                                                                                session_start();                          if (isset($_SESSION['username'])==FALSE)                          {                                 header("Location:http://www.domain.com/Staff/loginform.php");                                                           exit;                          }                         echo "Welcome ".$_SESSION['username']."!". "Logon time is: ".Date("m/d/Y");                         require($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php'); ?>

Could please anyone suggest something?Thank you in advance,Xenia

Link to comment
Share on other sites

Actually i manage to solve part of the problem.I manage to let users to login to the website by changing the following part of the code "check_login" and instead of "require" i put "include"

//How it was beforeheader("Location: http://www.domain.com/Staff/check_login.php");

//How i change itinclude("check_login.php");

Now i am trying to put this code to all the pages in order to include the appropriate menu.I manage to do it for only two pages the rest doesn't let me change it.

if($_SESSION['username']){       echo "Welcome ".$_SESSION['username']."!". "Logon time is: ".Date("m/d/Y");        include($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php');

More specific I will display an example of the code that i want the menu to appear:

  <?include "../dbconnect.php";//This is the new code i add to check if the user is admin or notsession_start();if($_SESSION['username']){echo "Welcome ".$_SESSION['username']."!". "Logon time is: ".Date("m/d/Y"); include($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php');?><form action="search1.php" method="get" name="Searchform"><table width="100%" height="100%" border="0" bordercolor="#DCCA23" bgcolor="#DCCA23"><tr bordercolor="#DCCA23" bgcolor="#DCCA23"><td height="10%" colspan="2"><font size="4" face="Perpetua"><h3><strong>Search Form </strong></h3></td></tr><tr bordercolor="#DCCA23" bgcolor="#DCCA23"><td height="10%" colspan="2"> <size="2" face="Perpetua"><h4>Search:<input name="searchval" type="text" id="searchval" size="40"><input type="submit" name="Search" value="Search"></h4></td></tr><tr><td><a href="advancesearch.php">Advanced Search</a></td></tr></table></form><?}else{header("Location:http://www.domain.com/Staff"); die();};?>

Does anyone knows what migh be the problem?I can't find any problem.I would really appriciate your help.Thank you in advance,Xenia Kalogeropoulou

Hi everyone,I have a problem with the login of the users.The first page of my website have a form where the user has to write his/her username and password(loginform.php). When the user clicks the submit button the user is being redirected to the page where the user being authenticated(password_input.php). The user  might be either administrator or regular user.If the administrator logins the pages will include a specific navigation menu(logoffheaderAdmin.php).if a regular user logins then another navigation menu appears(logoffheader.php). In order the system to know which menu to display will check with the page check_login.php. The problem now is that the user cannot login.When the user enters the correct details it just appears a blank page.if the user enters wrong details it just display that "Your password is not correct. Please log on again!".I think that the problem might be in the "password_input.php" page and specially with the "header()" function. The strange thing is that if i put the correct details and click submit the blank page will appear but if i add in the url  the address "http://www.domain.com/Staff/check_login.php" and manually redirect, it displays the correct menu. I will display the code that i have written and i would realy appreciate any help and suggestions.This is the code from the page "loginform.php"
<?      session_start();   if($_SESSION['username']){          echo $username.". You have logged on!";        require($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php');         }else{   ?><form action="password_input.php" method="POST" name = "login"><table align="center" bgcolor="#FFCC66">    <tr>           <td align="center" colspan="2">Log On</td>        </tr>        <tr>           <td>Username:</td>       <td><input type="text" name="uname"></td>        </tr>        <tr>           <td>Password:</td>       <td><input type="password" name="passwd"></td>    </tr>        <tr>           <td></td>           <td><input type="submit" value="Log in" name="submit"><input type="reset" value="Reset" name="reset"></td>        </tr></table></form><? }?>

This is the code for the page "password_input"

<?   session_start();   include "dbconnect.php";   if(empty($_POST['uname'])||empty($_POST['passwd'])){                   include("loginform.php");                    exit;   }    $uname= $_POST['uname'];    $query = "SELECT * FROM Webusers WHERE username='$uname'";    $result = mysql_query($query);    $row = mysql_fetch_array($result);    $encrypted_password = md5($_POST['passwd']);    if($encrypted_password!=$row['password']){         echo "<h3>Your password is not correct. Please log on again!</h3>";         include("loginform.php");    }else{                 $_SESSION['username']=$uname;         $_SESSION['isAdmin']=$row['admin']=='yes';         header("Location:http://www.domain.com/Staff/check_login.php");    }//var_dump($_SESSION);?>

This is the code for page "check_login.php"

 <?                                                                                                                                                                                                                                                                                session_start();                          if (isset($_SESSION['username'])==FALSE)                          {                                 header("Location:http://www.domain.com/Staff/loginform.php");                                                           exit;                          }                         echo "Welcome ".$_SESSION['username']."!". "Logon time is: ".Date("m/d/Y");                         require($_SESSION['isAdmin']?'logoffheaderAdmin.php':'logoffheader.php'); ?>

Could please anyone suggest something?Thank you in advance,Xenia

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...