Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Logging in and setting sessions

$
0
0

alright, this is a big screwy problem that I am trying to fix. The first thing is that I have a global php document loading into all php documents. The code is as follows:

<?php
session_start(); 
if(isset($_SESSION['username']))
 { 
header("Location: index.php"); exit();
include_once("connect.php");

//checking if sessions are set.
if(isset($_SESSION['username'])){
$session_username = $_SESSION['username'];
$session_pass = $_SESSION['pass'];
$session_id = $_SESSION['id'];

//check if the member exists
$query = mysql_query("SELECT * FROM clients WHERE id='$session_id' AND password='$session_pass'LIMIT 1") or die("Could not check member");
$count_count = mysql_num_rows($query);
if($count_count > 0){
//logged in stuff here
$logged = 1;

}else{
header("Location: logout.php");
exit();
}
}else if(isset($_COOKIE['id_cookie'])){
$session_id = $_COOKIE['id_cookie'];
$sessions_pass = $_COOKIE['pass_cookie'];


//check if the member exists
$query = mysql_query("SELECT * FROM clients WHERE id='$session_id' AND password='$session_pass'LIMIT 1") or die("Could not check member");
$count_count = mysql_num_rows($query);
if($count_count > 0){
while($row= mysql_fetch_array($query)){
$session_username = $row['username'];
}

//create sessions
$_SESSION['username']=$session_username;
$_SESSION['id']=$session_id;
$_SESSION['pass']=$session_pass;

//logged in stuff here
$logged = 1;

}else{
header("Location: logout.php");
exit();
}
}else{
//if the user is not logged in
$logged = 0;
}


 }



?>

Now this page is loaded into my log-in page here:

<?php include_once("scripts/global.php");

if(isset($_POST['email'])){
$email = $_POST['email'];
$pass = $_POST['pass'];
$remember = $_POST['remember'];

//error handeling 
if((!$email)||(!$pass)){
$message = 'Please insert both fields';
}else{
// secure the data
$email = mysql_real_escape_string($email);
$pass = sha1($pass);
$query = mysql_query("SELECT * FROM clients WHERE email='$email' AND password='$pass' LIMIT 1" ) or die("Could not check member");
$count_query = mysql_num_rows($query);
if($count_query == 0){
$message = 'The information you entered is incorrect';
}else{
//start session
$_SESSION['pass'] = $pass;
while($row = mysql_fetch_array($query)){
$username = $_row['username'];
$id = $row['id'];
}
$_SESSION['username'] = $username;
$_SESSION['id'] = $id;
if($remember == "yes"){
//create cookies
setcookie("id_cookie",$id,time()+60*60*24*100,"/");
setcookie("pass_cookie",$pass,time()+60*60*24*100,"/");
}

header("Location: home.php");






}
}
}

?>

Now the first error is that I get is:

Warning: mysql_real_escape_string(): No such file or directory in /misc/12/000/267/023/7/login.php on line 13

Warning: mysql_real_escape_string(): A link to the server could not be established in /misc/12/000/267/023/7/login.php on line 13

Warning: mysql_query(): No such file or directory in /misc/12/000/267/023/7/login.php on line 15

Warning: mysql_query(): A link to the server could not be established in /misc/12/000/267/023/7/login.php on line 15
Could not check member

 

Now in result when I dont have global.php loaded and have connect.php loaded.- logging in works but there is no session set and the information from their row in the table is not available. 

 

Thanks

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles