Advanced Search

Results 1 to 3 of 3

Thread: Login no longer works

  1. #1
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Login no longer works

    For some reason a login script I've been using has suddenly decided to stop working and keeps returning the error "Unable to establish a DB connection"... despite the fact it doesn't use one in the first place. If it doesn't produce that error it simply returns to the page telling you to login rather than give you the main site.

    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.

    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; 2010</p></div>
    	
    	<!-- // Spectrum // End main structure -->
    	
    	
      </div>
    </div>
    
    </body>
    </html>

  2. The Following User Says Thank You to ChroniX For This Useful Post:

    infocusweb (06-12-2010)

  3. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,629
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Well, if it was working and now it's not, the simple rule is that something changed. There's nothing in this code that would return an error message about a database, so what on your site would? Are you actually being logged in, and then the page you are redirected to connects to a DB but can't find it?

    About going back to the login page - do the other pages on your site check for $_SESSION['login']? If it's not set do they send the user back to the login page? That might be happening too.

    You should also move your session_start() line to the very top, immediately after <?php . If anything (anything) is output to the browser, including an error message, before the session is started, then it won't work.
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  4. #3
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default hello

    i have set log in page and i have requirement that after a few second automatic log out the page so which type of coding use in php.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •