Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-07-2010, 10:30 AM Login loop
Junior Talker

Posts: 2
Trades: 0
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:

Code:
<?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>&nbsp;</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>&copy; 2009</p></div>
	
	<!-- // Spectrum // End main structure -->
	
	
  </div>
</div>

</body>
</html>
chronix is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-08-2010, 06:39 AM Re: Login loop
Andy Pugh's Avatar
Extreme Talker

Posts: 203
Name: Andy
Location: N.Ireland
Trades: 0
Hi Chronix,

Simple issue you're having here, you're stating - if(isset($_GET['login'])) { which isn't being set, change this is to

PHP Code:
 if(isset($_POST['username'])){ 
That'll do the trick for you.

Ta,
Andy
__________________

Please login or register to view this content. Registration is FREE
Andy Pugh is offline
Reply With Quote
View Public Profile
 
Old 06-09-2010, 06:47 AM Re: Login loop
Junior Talker

Posts: 2
Trades: 0
Quote:
Originally Posted by Andy Pugh View Post
Hi Chronix,

Simple issue you're having here, you're stating - if(isset($_GET['login'])) { which isn't being set, change this is to

PHP Code:
 if(isset($_POST['username'])){ 
That'll do the trick for you.

Ta,
Andy
That didn't work. It also works perfectly find on one server but not the others so I can't understand why some of the code would need changing :s
chronix is offline
Reply With Quote
View Public Profile
 
Old 06-09-2010, 06:53 AM Re: Login loop
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Im fairly sure session_start() needs to be at the top of the file, you will also encounter issues with using headers in the middle of the script without using output buffering.

The headers will cause an error along the lines of ERROR: Headers already sent......
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-09-2010, 06:55 AM Re: Login loop
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Try pasting this at the top of the file, replacing <?php.

PHP Code:
<?php
session_start
();
ob_start();
and then delete session_start(); from above the if statement.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-09-2010, 08:31 PM Re: Login loop
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
This script should work fine, I tested on my localhost and no problems. The only advice I have is to add exit; after sending the header.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 04:29 AM Re: Login loop
Skilled Talker

Posts: 90
Name: Rob Cook
Trades: 0
i think from this you will get correct your thing

<?php
session_start
();
ob_start();

Last edited by chrishirst; 06-12-2010 at 06:40 PM..
robcook is offline
Reply With Quote
View Public Profile Visit robcook's homepage!
 
Old 06-10-2010, 04:59 AM Re: Login loop
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Quote:
Originally Posted by robcook View Post
i think from this you will get correct your thing

<?php
session_start
();
ob_start();
Looks familiar :P
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Reply     « Reply to Login loop
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27245 seconds with 12 queries