Jump to content

[SOLVED] login and session problem


daneth1712

Recommended Posts

Hi guys,

 

I have another problem....

 

these scripts were working fine, and I dont know what has changed to make them stop working...

:facewall:

 

 

I have a login page, with username and password fields.

 

these then get sent to the page below;

 

<?php
$username=($_POST['username']);
$password=($_POST['password']);

//send back to the login form if page is called from other location
if (!isset($username) || !isset($password)) {
header( "Location: admin_login.html" );
}
elseif (empty($username) || empty($password)) {
header( "Location: admin_login.html" );
}
else{
//set the database connection variables
include('includes/config.php');

//connect to the database
$db = mysql_connect("$hostname", "$adminuser", "$adminpass") or die ("Error connecting to database.");
mysql_select_db("$database", $db) or die ("Couldn't select the database.");
$result=mysql_query("SELECT * FROM $dbaccounts WHERE username='$username' AND password='$password'", $db);

//check that at least one row was returned
$row = mysql_num_rows($result);
if($row == 1){
while($row = mysql_fetch_array($result)){

//start the session and register variable to password
session_start();
$_SESSION['password']= $array['password'];
header( "Location: adminlogin_successful.php" );
}		
}
else {
//if nothing is returned
header( "Location: adminlogin_error.html" );
}
}
?>

 

If correct, it should go to another page which calls for

<?php

include('includes/sess_password.php');

?>

 

the sess_password.php page is below;

 

<?php
//start the session
session_start();

//check to make sure the session username variable is registered
if(isset($_SESSION['password'])){
$passw_id=$_SESSION['password'];
}
else{
//the session variable isn't registered, send them back to the login page
header( "Location: admin_login.html" );
}
?>

 

Where am I going wrong... I would have a guess at the sess_password.php page that calls for the session... Any help is really appreciated!

Link to comment
https://forums.phpfreaks.com/topic/169067-solved-login-and-session-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.