waterwn1097 Posted December 10, 2013 Share Posted December 10, 2013 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 13Warning: mysql_real_escape_string(): A link to the server could not be established in /misc/12/000/267/023/7/login.php on line 13Warning: mysql_query(): No such file or directory in /misc/12/000/267/023/7/login.php on line 15Warning: mysql_query(): A link to the server could not be established in /misc/12/000/267/023/7/login.php on line 15Could 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 Quote Link to comment https://forums.phpfreaks.com/topic/284667-logging-in-and-setting-sessions/ Share on other sites More sharing options...
Solution jazzman1 Posted December 10, 2013 Solution Share Posted December 10, 2013 (edited) 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 December 10, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/284667-logging-in-and-setting-sessions/#findComment-1461896 Share on other sites More sharing options...
waterwn1097 Posted December 10, 2013 Author Share Posted December 10, 2013 second file is login.php the script with the login credientials is connect.php which is included on global.php. I will move the session information below the include connect.php and remove the exit and see what happens. thanks Quote Link to comment https://forums.phpfreaks.com/topic/284667-logging-in-and-setting-sessions/#findComment-1461904 Share on other sites More sharing options...
jazzman1 Posted December 10, 2013 Share Posted December 10, 2013 You need to redesign the logic of the script too Do you know what a header() and exit() functions do? Quote Link to comment https://forums.phpfreaks.com/topic/284667-logging-in-and-setting-sessions/#findComment-1461905 Share on other sites More sharing options...
waterwn1097 Posted December 10, 2013 Author Share Posted December 10, 2013 yep the exit() was the issue.. I wonder how that got there.. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/284667-logging-in-and-setting-sessions/#findComment-1461908 Share on other sites More sharing options...
waterwn1097 Posted December 10, 2013 Author Share Posted December 10, 2013 well in the current script header() means if the variable matches send to whatever URL right? then exit() just clears the current script and moves to the next? Quote Link to comment https://forums.phpfreaks.com/topic/284667-logging-in-and-setting-sessions/#findComment-1461909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.