Jump to content

Simple login issues


Athmaus

Recommended Posts

Hello,

 

I created a simple login script, taht has a hard coded user/pass. Yet for some reason it will not work, keeps redirecting to the main login page

 

Here is the code

 

Login Page

<table width='400' border='0' align='center' cellpadding='0' cellspacing='0'>  
  <tr>  
    <td>UserName:</td>  
    <td><form action="loginscript.php" method="post"> <input name="username" type="text" size="10"></td>  
  </tr>  
  <tr>  
    <td>Password:</td>  
    <td><input name="password" type="password" size="10"></td>  
  </tr>  
  <tr>  
    <td colspan='2' align='center'><input name="Submit" type="submit" value="Submit"></form></td>  
  </tr>  
</table> 

 

 

Login Script

<?php 
session_start(); 

$pass = strtolower($_POST['password']); 
$name = strtolower($_POST['username']); 

if($name == "test" && $pass == "test"){ 
header ("location: select.php"); 
} 
else{ 
// invalid login, so go back ... 
header ("location: index.php"); 
} 

?> 

 

Select.php

<?php 
session_start(); 
if(isset($_SESSION['myuser'])){ 

} 
else{ 
header ("location: index.php"); 
} 
?> 

 

ANy ideas why it is not working. It doesnt seem like it is going through the login on the loginscript as all it does is redirect back to index page over and over again

Link to comment
Share on other sites

I cahnged the loginscript to this

 

<?php  
session_start();  

$pass = strtolower($_POST['password']);  
$name = strtolower($_POST['username']);  

if($name == "test" && $pass == "test"){  
$_SESSION['myuser']=$name;  
header ("location: select.php");  
}  
else{  
// invalid login, so go back ...  
header ("location: index.php");  
}  

?> 

 

still no luck

Link to comment
Share on other sites

First, ALWAYS put an exit after any header() redirect. Without the exit(), php will continue running code until the browser actually receives and acts on the redirect. That could be the problem here.

 

loginscript.php

<?php  
session_start();  

$pass = strtolower($_POST['password']);  
$name = strtolower($_POST['username']);  

if($name == "test" && $pass == "test"){  
  $_SESSION['myuser']=$name;  
  header ("location: select.php");  
  exit;
}  else{  
  // invalid login, so go back ...  
  header ("location: index.php");  
  exit;
}  

?> 

 

select.php

<?php 
session_start(); 
if(isset($_SESSION['myuser'])){ 

} else{ 
  header ("location: index.php"); 
  exit;
} 
?> 

 

If that does not solve it. Put an echo before each header() that says something like: "In login redirect to index".  This will break the redirect, but at least we can figure out whether it is the loginscript header or the select header that is causing the redirect to index.php.

Link to comment
Share on other sites

got it to work

 

<?php

session_start();
$pass = strtolower($_POST['password']);
$name = strtolower($_POST['username']);
if ($name == "test" && $pass == "test") {
   $_SESSION['myuser'] = $name;
   session_write_close();
   header("Refresh: 0; url='select.php'");
} else {
   // invalid login, so go back ...
  header("Refresh: 0; url='index.php'");
}
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.