coolphpdude Posted March 31, 2008 Share Posted March 31, 2008 Hi there. I'm transferring my work from my uni hosting page to my home webpage. Ive recreated the databases exactly so they are identicle (and double checked this) i've changed the connection information at the beginning of each of my php pages. my problem lies with sessions! For some reason the code which works on my uni website and holds the following sessions throughout my site works, but not at home! // take the user id into the session id called user_session_id $_SESSION['user_session_id'] = $user_id; // take the login password into the session id called user_session_password $_SESSION[user_session_password'] = $user_password; // go to page header ("location: useraccount.php"); exit; now when i authenticate this user on the useraccount.php page theres no user found and ive narrowed it down to the sessions. my authentication is... // Run user query (checks if the login credentials are correct) $user_result = mysql_query("SELECT * FROM user WHERE user_id='$user_session_id' and user_password='$user_session_password'",$db); Any idea why this might be?? Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/ Share on other sites More sharing options...
MadTechie Posted March 31, 2008 Share Posted March 31, 2008 you need to have use session_start(); on the uni sever they might have autostart.sessions turn on also i assume you have $user_session_id = $_SESSION['user_session_id'] on pages that don't already have $user_session_id set! Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-505475 Share on other sites More sharing options...
coolphpdude Posted March 31, 2008 Author Share Posted March 31, 2008 ive got... <?php session_start(); at the beginning of every page. i set the session on the login code before automatically sending the logged in user to the useraccount.php page so it shud be carried over in the session shudnt it? this is the way i have done it when i originally created the site and it worked fine Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-505478 Share on other sites More sharing options...
MadTechie Posted March 31, 2008 Share Posted March 31, 2008 quick example <?php session_start(); $_SESSION['test'] = "Hello World"; ?> <?php session_start(); echo $_SESSION['test']; //Note NOT $test ?> Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-505479 Share on other sites More sharing options...
coolphpdude Posted March 31, 2008 Author Share Posted March 31, 2008 right, ive added this to the start of my page $user_session_id = $_SESSION['user_session_id']; $user_session_password = $_SESSION['user_session_password']; ...and it now works. any idea why i didnt need to do this on my original site??? Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-505480 Share on other sites More sharing options...
coolphpdude Posted March 31, 2008 Author Share Posted March 31, 2008 Well it works now so thats great, thanks mate, much appreciated again!! Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-505487 Share on other sites More sharing options...
MadTechie Posted March 31, 2008 Share Posted March 31, 2008 yeah,, they have register global on, which is a bad thing for them see here http://www.php.net/manual/en/security.registerglobals.php Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-505491 Share on other sites More sharing options...
coolphpdude Posted April 2, 2008 Author Share Posted April 2, 2008 Ok, new problem, im guessing its caused by the same issue though!! If i was allow the user to select a link and send an id accross it by doing the following... printf("<tr><td><a href=\"postselection.php?id=%s\">%s</a></td>", $post_row["post_id"], $post_row["post_id"]); ...it would work on my previous webpage but not on my new hosting. to test to see if the variable is being passed accross i used... echo "$id"; .... and nothing was output so im guessing its not holding the variable when moving to the next page. any idea's?? Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-507270 Share on other sites More sharing options...
coolphpdude Posted April 2, 2008 Author Share Posted April 2, 2008 or at least know a way round it?? Quote Link to comment https://forums.phpfreaks.com/topic/98784-sessions/#findComment-507288 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.