Jump to content

Login loop


ChroniX88

Recommended Posts

For some reason a login script I've been using has suddenly decided to stop working. The script is being used in three locations. It has stopped working on my local server and on an external server. On the other external server it is working though. I have tried downloading the files from the working server to use on others but it won't work and rather than return the main page, it loops back to the login page.

 

Can anybody see what the problem might be?

 

Login.php:

 

<?php 
$TARGET = "/"; // go to this page if login ok
//SETUP, insert your users and passwords
$users = array("demo", "admin");
$passwords = array("demo_pass", "password");


session_start();
if(isset($_GET['login'])){	
	for($i=0; $i!= sizeof($users); $i++){
		if($users[$i] == $_POST['username']){
			if($passwords[$i] == $_POST['password']){
				$_SESSION['login'] = true;
				header("location: ".$TARGET);
			}
		}
	}
	$msg = "An error occurred. Please try again.";
}
?>









<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Extranet</title>
<link href="/templates/Spectrum/master.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="container">
  <div id="innerCont">


<!-- // Spectrum // Begin main structure -->


<div class="mastWarn">
<h2>Protected Content</h2>
<p>To access this content you must be a member of staff. Contact the Station Manager for login information.</p>
</div>

<div id="content">	

<!-- // Spectrum // Page Content -->


<form id="form1" name="form1" method="post" action="?login">
  <table width="370" border="0">
    
    <?php if(isset($msg)) echo "<tr>
      <td colspan=\"2\" class=\"error\">".$msg."</td>
    </tr>";?>
   
    
    <tr>
      <td width="175"><div align="right"><strong>Username:</strong></div></td>
      <td width="185"><label>
        <input type="text" name="username" value="demo"/>
      </label></td>
    </tr>
    <tr>
      <td><div align="right"><strong>Password:</strong></div></td>
      <td><label>
        <input type="password" name="password" value="demo_pass"/>
      </label></td>
    </tr>
    <tr>
      <td> </td>
      <td><label>
        <input type="submit" name="button" id="button" value="Login" />
      </label></td>
    </tr>
  </table>
</form>

<p>Testing Login<br /><br />Username: demo<br />Password: demo_pass
<hr />


<!-- // Spectrum // End Page Content -->
    </div>
<div id="footer"><hr /><p>© 2009</p></div>

<!-- // Spectrum // End main structure -->


  </div>
</div>

</body>
</html>

Link to comment
Share on other sites

Your form action makes no sense? ?login

 

If you are trying to get it to post to itself then you need to set your action blank or to Login.php

 

like one of the following

 

action="" or action="Login.php"

 

EDIT: Nevermind i see what you did... that's odd though. I don't know why you would use a mix of those types. POST and GET should not be used interchangeably I believe that is probably bad practice.

 

Does it do anything else other than just reload the page?

Link to comment
Share on other sites

aeroswat, programmers put GET parameters onto the end of URL's in POST method forms all the time to distinguish what action to take in the form processing code. Here is the one that this forum used for this reply -

action="http://www.phpfreaks.com/forums/index.php?action=post2;start=0;board=1"

 

Link to comment
Share on other sites

aeroswat, programmers put GET parameters onto the end of URL's in POST method forms all the time to distinguish what action to take in the form processing code. Here is the one that this forum used for this reply -

action="http://www.phpfreaks.com/forums/index.php?action=post2;start=0;board=1"

 

In that case why not use various submit POST variables then? It would seem that there would be no need to use a GET variable in a form that uses POSTs since as far as I know the main reason to use GETs are so that users can bookmark pages. I apologize for my previous post because I had assumed that most people would take this route. Please educate me a little more on the subject as I suppose I don't fully understand the reason for the 2

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.