GreenFanta Posted November 27, 2010 Share Posted November 27, 2010 Basically, I've developed a basic registration and login code whereby it inserts and retrieves data from MySQL, however my login code is giving me problems in a sense that I don't understand the concept of the "session" feature, my understanding of it, is that it places a cookie on your computer and verifies it on each request called by the page with the start_session() function on it, if so, is this correct? My Header for all pages: <?php session_start(); ?> When the client logs in successfully: $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; // Both Local variables ($myusername and $mypassword) are from the matching database and client entered values. When the client navigates to a completely different page: if (isset($_SESSION['myusername'])) { // Do x } else { // Do y } // It is never doing X for me. Thanks! Regards Matthew Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/ Share on other sites More sharing options...
revraz Posted November 27, 2010 Share Posted November 27, 2010 1. Make sure you use session_start() at the top of each page that uses them. 2. Try it and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140287 Share on other sites More sharing options...
papaface Posted November 27, 2010 Share Posted November 27, 2010 Always remember, sessions are stored on the server, NOT the computer of the person viewing the page. For that, you need cookies. Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140288 Share on other sites More sharing options...
GreenFanta Posted November 27, 2010 Author Share Posted November 27, 2010 1. Make sure you use session_start() at the top of each page that uses them. 2. Try it and see if it works. At the top of each page it says session_start but that doesn't make a difference. Basically, they log in and the session keeps them logged in, but it's not working Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140290 Share on other sites More sharing options...
revraz Posted November 27, 2010 Share Posted November 27, 2010 We would need to see all your code and not just a snippet to see why. Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140292 Share on other sites More sharing options...
GreenFanta Posted November 27, 2010 Author Share Posted November 27, 2010 Well, it just displays HTML through if functions in PHP, all I'm really trying to do is when the user uses my login interface then it must register the session, I have used session_start() on every single page and (since its in the header which is included in every page) and the header also goes to an if(isset($_SESSION['myusername'])) , so it's mainly the header that's checking whether the user is logged in or not and then it adjusts the menu buttons appropriately, and that's all I'm trying to do, and I've provided the only code that would logically make a difference to the session as nothing happens in between with any variables etc.. Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140293 Share on other sites More sharing options...
revraz Posted November 27, 2010 Share Posted November 27, 2010 You haven't shown us how these two variables get set. $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; And why come here asking for help when you won't provide the info? Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140294 Share on other sites More sharing options...
GreenFanta Posted November 27, 2010 Author Share Posted November 27, 2010 $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; Which are taken from the login form created to allow users to login Quote Link to comment https://forums.phpfreaks.com/topic/219986-a-poor-understanding-of-sessions/#findComment-1140295 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.