rmmo Posted July 3, 2008 Share Posted July 3, 2008 hi all. im trying to figure out the best way to do this: when my user enters his/her username and password into a form they are posted to the next page where they are assigned to $username and $password and then checked against the database (this all works). now i want to use these two bits of data on vitrually ever subsiquent page... is there any way to carry them over to all the other pages other than making invisible forms to post them? (i allready have forms posting other data.) if so could someone explain how i could do it. thanks very much for reading and thanks in advanced for any help you may be able to offer. RMMO Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/ Share on other sites More sharing options...
papaface Posted July 3, 2008 Share Posted July 3, 2008 sessions: session_start(); $_SESSION['username'] = $_POST['username']; Must have session_start(); at the top of every page you want to use/create/edit session vars. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580876 Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 Hidden form fields are awful; use sessions. You only need to store one value - the username, or whatever is the primary key of the table that stores the users - since you've already done the check against the database. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580879 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 @TransmogriBenno: He should store the whole user data array that he gets from the query in the session so he doesn't need to requery again just to display say...the username or something. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580885 Share on other sites More sharing options...
.josh Posted July 3, 2008 Share Posted July 3, 2008 @TransmogriBenno: He should store the whole user data array that he gets from the query in the session so he doesn't need to requery again just to display say...the username or something. I disagree. If a session is hijacked, I'd rather only a single abstracted id be available to the hacker than all the info on a silver platter be just handed to them. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580887 Share on other sites More sharing options...
thatsgreat2345 Posted July 3, 2008 Share Posted July 3, 2008 But if he utilizes some techniques such as changing session ID with http://php.net/session_regenerate_id will hijacking really be a major issue? Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580890 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Unless you echo the password out, they can't do anything with the session. The session being hijacked only means that the "hacker" can access things that the user could access, which is no less secure than just storing the session ID. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580892 Share on other sites More sharing options...
.josh Posted July 3, 2008 Share Posted July 3, 2008 But if he utilizes some techniques such as changing session ID with http://php.net/session_regenerate_id will hijacking really be a major issue? It makes it harder, but not impossible. Unless you echo the password out, they can't do anything with the session. The session being hijacked only means that the "hacker" can access things that the user could access, which is no less secure than just storing the session ID. Okay well then how about packet sniffing? Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580895 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 But you're not transferring the password over TCP/IP, it's just stored in the session. Hijacking sessions and actually robbing your server of the session files are two completely different things. Unless you had a page like: hackme.php session_start(); echo serialize($_SESSION); Password: $_SESSION['password']; You should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580896 Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 @DarkWater I agree re: storing additional data in the session, under 2 conditions: 1. The other data needs to be displayed somewhere (it might not, I build a lot of systems in which this is the case) - best to store as little data in the session as possible. 2. The session is updated as soon as the row is updated by the user, e.g. if there's an "update my details" form - stale data is ugly. There is also an issue if the actions of admins or others affect the situation, e.g. if an admin bans or deletes a user, you need to check the database every time they view a page, otherwise they can stay on until their session times out. Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580897 Share on other sites More sharing options...
rmmo Posted July 3, 2008 Author Share Posted July 3, 2008 great, that worked a treat! interesting disccusion guys.. i think you came to an agreement at the end of it... both ideas are great depending on the needs of the system... ill just store the usrnm and paswd in this case as they are the only bits i need later on. thanks to both of you! my problem is answered! so this post is <SOLVED> Quote Link to comment https://forums.phpfreaks.com/topic/113085-solved-whats-the-best-way-to-transfer-variables-between-pages/#findComment-580972 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.