Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php redirecting after password approved

Status
Not open for further replies.

estrellas

Programmer
Jul 16, 2004
48
US
Hey guys - I'm trying to make it where users can sign into my database and then if their password is approved, they'll be sent to another page. here's the login script i'm using
Code:
<?php

//this initiates a session
session_start();

//see if there is a cookie that is both logged in the session we are in
if($_COOKIE['logedin'] == 'yes' || $_SESSION['logedin'] == 'yes') {

    //if the cookie is there or the session is logged in , then include the header login.php
	header("Location: login.php");

	//exit successfully
	exit();
}

// If the form was submited check if the username and password match
if($_POST['Submit']){
	
	//assign a variable to the username the user input
	$username = $_POST['user'];

	//assign a password to the username the user input
	$password = $_POST['pass'];
	
if ($username=="user" && $password=="pass"){
		// If username and password is right , store the session in a cookie
		setcookie ('logedin', 'Admin Access',time()+30000); // Set the length of the cookie to 30000
		
		//Create the Session id's (as many as you want, can also do the same with cookied)
		$_SESSION['logedin'] = ' Admin Access';
		
		//close the database
		@mysql_close();
		
		// Redirect to the page
		header("Location: /admin/insert.php");
		
		//exit successfully
		exit();

	} else {
	
		//print this to the screen
		$error = 'Password and/or Username Not Valid, Please Try Again!';
		
		//close the database
		@mysql_close();
	}
}

?>
the rest of the page contains the html stuff to connect .. here it is
Code:
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="adminlogin" id="adminlogin">
  <table width="30%" border="5" align="left" cellpadding="5" cellspacing="0">
    <tr bgcolor="#000000"> 
      <td colspan="2"><div align="center"><font color="#FFFFFF"><strong>PLEASE 
          LOG IN:</strong></font></div></td>
    </tr>
    <tr> 
      <td width="47%"><strong>Username:</strong></td>
      <td width="53%"><input name="user" type="text" id="user" ></td>
    </tr>
    <tr> 
      <td><strong>Password:</strong></td>
      <td><input name="pass" type="password" id="pass" ></td>
    </tr>
    <tr> 
      <td colspan="2"><div align="center"><strong>
          <input name="Submit" type="submit" id="Submit"  value="Click Here To Sign-In">
          </strong> </div></td>
    </tr>
  </table>
  <table width="60%" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td height="50"><div align="center"><strong><font color="#FF0000"><?php echo $error; ?></font></strong></div></td>
    </tr>
  </table>
</form>

now after the person pushes Sign In, i want it to take them to /admin/insert.php. this isn't working for some reason. i have this header included at the top of every page i want to be password checked too...
Code:
<?php

//this information is so everyone doesn't have access to changing records
if($_SESSION['logedin'] != 'Admin Access' || $_SESSION['logedin'] != 'Admin Access'){

header("Location: /anss/station_info/login.php"); 

exit(); 

} ?

do you have any ideas on how I can get these pages to redirect. currently when i type in the correct name/password, all that happens is that the page stays at login.php

thanks much in advance :)
cheers!

-------
 
1. Are you sure you mean this:
If there is the cookie set to logedin or the session go to login.php?
Code:
if($_COOKIE['logedin'] == 'yes' || $_SESSION['logedin'] == 'yes') {

    //if the cookie is there or the session is logged in , then include the header login.php
    header("Location: login.php");

    //exit successfully
    exit();
}

2. This is twice the same:
Code:
//this information is so everyone doesn't have access to changing records
if($_SESSION['logedin'] != 'Admin Access' || $_SESSION['logedin'] != 'Admin Access'){
Did you mean one of them to be $_COOKIE?
Also consider the logical OR operator. If either one fails it will redirect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top