per1os Posted June 7, 2007 Share Posted June 7, 2007 I will test it out when I get home the exact code on my server. If I can do it on my server than there is something definitely wrong at the server level and not at the script. Other than a few spots that could use improvement (which shouldn't effect the session) I do not see anything that would be throwing the sessions out of whack. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-270289 Share on other sites More sharing options...
Trium918 Posted June 8, 2007 Author Share Posted June 8, 2007 Why won't the session register in the user_auth.php file? Ok, I will brake the code down. I am asking for someone to point out the problem! Note: Follow the order in which there in. The user is prompted to log in from login.php. The form is submitted to member.php. There is a call to a function called login($user_name,$password) which is defined in user_auth.php. The other two files are the database file and container_fns.php. The structure of how the database is set up is in the database file. login.php <form method="POST" action="member.php"> <h1 align="center">Test log in </h1> <table border="1" align="center"> <tr> <td>Username:</td> <td><input type="text" name="user_name" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> member.php <?php session_start(); require_once("container_fns.php"); if (isset($_POST['submit'])) #They have just tried logging in { $user_name= trim($_POST['user_name']); $password = trim($_POST['password']); #Checks that username is in database and password is correct $result = login($_POST['user_name'], $_POST['password']); // If user isn't valid if(!$result){ // unsuccessful login echo "<p class='genmed'>You could not be logged in. You must be logged in to view this page. <br /> $user_name $password</p>"; exit; } // if they are in the database register the user id $valid_user = $user_name; $_SESSION['valid_user']= $valid_user; $password_str = $password; $password_str = md5($password_str); $_SESSION['password'] = $password_str; }// end of submit // connect to database // retrieve default image $sql = "SELECT default_image FROM members_info WHERE members_id='{$_SESSION['memberid']}'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { $default_image = $row['default_image']; echo "<img src=\"$default_image\" height=\"120\" width=\"120\" alt=\" \" />"; } } else { echo "No results found"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> user_auth.php <?php require_once("db_fns.php"); function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $query = "SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password') LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result) > 0) { $row=mysql_fetch_assoc($result); $memberid = $row['members_id']; $_SESSION['memberid'] = $memberid; $last=$row['last_visit']; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $sql="UPDATE members_info SET last_visit=NOW() WHERE members_id='{$_SESSION['memberid']}'"; //now only update it $result2=mysql_query($sql); }else{ echo "No results found"; return false; } }else { echo "Query failed<br />$query<br />" . mysql_error(); return false; } return true; } ?> db_fns.php <?php // connects to the database function db_connect() { $result = mysql_pconnect("localhost"/*, " ", " "*/); if (!$result) return false; if (!mysql_select_db("trust_me")) return false; return $result; } // structure of the database /* drop table if exists members_info; create table members_info(members_id int unsigned not NULL auto_increment primary key, user_name varchar(25) not NULL, first_name varchar(25) not NULL, last_name varchar(25) not NULL, gender varchar(6) not NULL, birth_month varchar(9) not NULL, birth_day tinyint(2) not NULL, birth_year int(4) not NULL, contact_number varchar(10) not NULL, email_address varchar(100) not NULL, register_date datetime not NULL default'0000-00-00',password varchar(32) not NULL, last_visit datetime not NULL default'0000-00-00',default_image varchar(50) not NULL); */ ?> container_fns.php <?php // I can include this file in all of my files // this way, every file will contain all of the functions require_once("db_fns.php"); require_once("user_auth.php"); ?> *bump* Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-270764 Share on other sites More sharing options...
per1os Posted June 8, 2007 Share Posted June 8, 2007 It's your server. The code works just fine. echo "<img src=\"http://localhost/trium/$default_image\" height=\"120\" width=\"120\" alt=\" \" />"; echo "<br />" . $_SESSION['memberid'] . "<Br />" . $_SESSION['last']; That was the only part I changed to show the image, memberid from session and last from session. See attached screenshot. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271185 Share on other sites More sharing options...
Trium918 Posted June 9, 2007 Author Share Posted June 9, 2007 It's your server. The code works just fine. echo "<img src=\"http://localhost/trium/$default_image\" height=\"120\" width=\"120\" alt=\" \" />"; echo "<br />" . $_SESSION['memberid'] . "<Br />" . $_SESSION['last']; That was the only part I changed to show the image, memberid from session and last from session. See attached screenshot. But it's on localhost! Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271437 Share on other sites More sharing options...
per1os Posted June 9, 2007 Share Posted June 9, 2007 It's your server. The code works just fine. echo "<img src=\"http://localhost/trium/$default_image\" height=\"120\" width=\"120\" alt=\" \" />"; echo "<br />" . $_SESSION['memberid'] . "<Br />" . $_SESSION['last']; That was the only part I changed to show the image, memberid from session and last from session. See attached screenshot. But it's on localhost! Whats wrong with that? I can test on a live server if you want, I guarantee it will work on my server as I have my localhost setup the exact same. If you want me to, I will. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271565 Share on other sites More sharing options...
Trium918 Posted June 9, 2007 Author Share Posted June 9, 2007 Yea, but why isn't it working on my server? I need some help figuring this out. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271572 Share on other sites More sharing options...
per1os Posted June 10, 2007 Share Posted June 10, 2007 Post your php.ini settings. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271669 Share on other sites More sharing options...
Trium918 Posted June 10, 2007 Author Share Posted June 10, 2007 Post your php.ini settings. php.ini file Attached. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271809 Share on other sites More sharing options...
per1os Posted June 10, 2007 Share Posted June 10, 2007 The only difference I saw in the session portion was: session.use_only_cookies = 1 that, yours is defaulted to 0, where as mine was set to 1. Whether that should or would make a a difference I doubt it. You could try setting the domain for the session cookie bit via www.php.net/ini_set Other than that I have no clue, all I can see if that it worked for me. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271827 Share on other sites More sharing options...
Trium918 Posted June 10, 2007 Author Share Posted June 10, 2007 What version of apache are you running? The thing that I donnot understand is why would redundant code work? The sessions are being register when I am using the script below. <?php function login($user_name, $password) // check username and password with db // if yes, return true // else return false { // connect to db $conn = db_connect(); if (!$conn) return 0; $result = mysql_query("SELECT * FROM members_info WHERE user_name='$user_name' AND password=MD5('$password')"); if ($result){ $sql1="SELECT members_id,last_visit FROM members_info WHERE user_name='$user_name'"; $result1=mysql_query($sql1); $row=mysql_fetch_assoc($result1); $last=$row['last_visit']; $membersid=$row['members_id']; $_SESSION['membersid'] = $membersid; #Display date as 5/8/2007 format $last = date('n/d/Y', strtotime($last)); $_SESSION['last']=$last; //use the session variable to hold the previous last visit date. $sql="UPDATE members_info SET last_visit=NOW() WHERE user_name='$user_name'"; //now only update it $result2=mysql_query($sql); } if (!$result) return 0; if (mysql_num_rows($result)>0) return 1; else return 0; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271848 Share on other sites More sharing options...
per1os Posted June 10, 2007 Share Posted June 10, 2007 Apache 2.0 Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-271923 Share on other sites More sharing options...
Trium918 Posted June 19, 2007 Author Share Posted June 19, 2007 Ok, frost110, I tried the script on Linux server and for some reason the session still is registering. What could be the problem? What do you suggest I try? Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-277680 Share on other sites More sharing options...
per1os Posted June 19, 2007 Share Posted June 19, 2007 I dunno man, you posted all relevant code, it seems your settings are alright. Really a default installation of PHP and Apache should work just fine. I cannot re-create the error on my box, linux or windows. Is there any portion of code that is being ran that you have not posted? Are you using Header redirects, if you are using a header redirect try a javascript or meta instead. Other than that you stumped me man, as it works fine on my linux and windows servers. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-277688 Share on other sites More sharing options...
Trium918 Posted June 19, 2007 Author Share Posted June 19, 2007 I dunno man, you posted all relevant code, it seems your settings are alright. Really a default installation of PHP and Apache should work just fine. I cannot re-create the error on my box, linux or windows. Is there any portion of code that is being ran that you have not posted? Are you using Header redirects, if you are using a header redirect try a javascript or meta instead. Other than that you stumped me man, as it works fine on my linux and windows servers. Yes, I am using a redirect, but I will have to post it when I get home. I donnot have the code with me. Quote Link to comment https://forums.phpfreaks.com/topic/54486-question/page/2/#findComment-277700 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.