Jump to content

Logging in and setting sessions


waterwn1097
Go to solution Solved by jazzman1,

Recommended Posts

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

 

Link to comment
Share on other sites

  • Solution

What's the name of the second file you've posted above? Where is the script with mysql database credentials and what's the name of it and where do you include it before using all mysql_* functions?

 

EDIT: Take a note that you are using exit() on the line #5!

Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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