MadnessRed Posted December 18, 2008 Share Posted December 18, 2008 HI, I have online game, it works fine, however you cant log in more to more than 2 sections at once, (which is needed). Is there a way to store user data without sessions or cookies, i just want to store 1 integer <100, which will tell the game what section the user is in. Is there a way to ad a $_GET to every link without doing it manually. Or can you have to SESSIONS runnign at once? I hope I am making sense Anthony Link to comment https://forums.phpfreaks.com/topic/137585-multiple-sessions-or-somethign-to-the-same-effect-how-can-i-do-it/ Share on other sites More sharing options...
phpian Posted December 18, 2008 Share Posted December 18, 2008 i take it these 'sections' are session independent from each other. Can you not store the data in a db or have you considered application variables? application variable work-around: http://www.leosingleton.com/projects/code/phpapp/ Link to comment https://forums.phpfreaks.com/topic/137585-multiple-sessions-or-somethign-to-the-same-effect-how-can-i-do-it/#findComment-719124 Share on other sites More sharing options...
MadnessRed Posted December 18, 2008 Author Share Posted December 18, 2008 basically what I would like, is to be able to open testpage.php, that then say sets $_SESSTION['time'] to time. Then i open teh same page in a new tab, and set a $_SESSION['time'] to the current time there. Then those two sessions on pages on different tabs can work together. So I can have the same session loaded twice if that makes sence. atm I am trying to do a regex replace on all links and to put a get variable onto all pages to see if that works but and easier way would be better. Link to comment https://forums.phpfreaks.com/topic/137585-multiple-sessions-or-somethign-to-the-same-effect-how-can-i-do-it/#findComment-719191 Share on other sites More sharing options...
thirdearth Posted December 18, 2008 Share Posted December 18, 2008 I actually have the same dilemma *I think* as MadnessRed. My login script uses Sessions in PHP. Now, when someone logs in, here is what happens: // Code begins here $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysqli_query($link,$qry); if($result) { if(mysqli_num_rows($result) == 1) { session_regenerate_id(); $member = mysqli_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_LOGIN'] = $member['login']; session_write_close(); mysqli_query($link,"UPDATE members SET online = 'yes' WHERE login = '$login'"); // Code ends here The result works absolutely fine. The problem lies in trying to sign on as more than 1 user on the same computer. Let's say "User 1" signs on. He does whatever he wants, but for some reason, he needs to be on 2 account *as a game example, maybe he needs to pass himself an item ingame from another character of his friend's*. So he logs onto "User 2" by opening a new window. What happens in my script is that the second login Session overrides the first, and now both windows are "User 2". Everytime it tries to pull $login, they both read the same Session. Is this the same kind of issue you are referring to Madness? Anyone have any ideas on how I can either make it set different Sessions, or get rid of Sessions completely for a login script? Link to comment https://forums.phpfreaks.com/topic/137585-multiple-sessions-or-somethign-to-the-same-effect-how-can-i-do-it/#findComment-719195 Share on other sites More sharing options...
phpian Posted December 19, 2008 Share Posted December 19, 2008 sorry guys, i left you in the dark there for a bit. i wrote a reply, hit the post button and then walked away thinking it was posted but it hadn't. anyway what i was gonna say was, if I'm understanding you right, you're actually trying to achieve the opposite of each other. madness, you are trying to use the same session variables across two different sessions, which is not possible. You will need to either use that application variable workaround i posted or you will need to store the data in a database. I don't fully grasp what you're trying to achieve. may be you just want to know when the last time someone accessed testpage.php. in which case, when the page is requested, query the database/text file for a previously stored time, save that - it'll be the answer, and then override it (or create a new entry if it wasn't found) with the current time. then when someone else comes along with a different session, they can still access the stored data so different sessions become irrelevant. But, as thirdearth pointed out, opening a new tab/window will sometimes keep the same session. i think it's down to what browser you are using. only after closing all open browsers of the same type (FF, IE, Safari etc), will end your session. actually don't quote me on that because i don't know that for sure but that's what usually happens. so your example you gave would actually work. you'd be able to access the same session variable if you opened the app in a new tab. thirdearth, i believe you are trying to do the opposite. you actually want a new session each time a new tab/window is opened. this is quite tricky. basically, i think this is down to browser settings and it should be possible to create two profiles in FF that use separate sessions. but that is on the client side and you have no way of controlling that server side. In IE a new window will create a new session. a new tab won't. ctrl+n won't. the only way i can think to solve this is long-winded and not very elegant. when the user logs in, generate a unique number and then append that to every link and form from then on. so user 1 logs in and gets given an id of 1. the page is then downloaded and all links/forms on the page has ?sid=1. so as they navigate through the app, they are passing 1 to each page. so all links/forms on every other page will append $_REQUEST['sid']. user 2 logs in and gets given and id of 2. all links generated from this will have ?sid=2. therefore you can now duplicate your session variables e.g. $_SESSION['blah_' . $REQUEST['sid']] = foo; which will give you $_SESSION['blah_1'] and $_SESSION['blah_2']. after all that, it's probably not much help at all but i didn't want to leave you hanging. these are just my thoughts on the subject and may not be 100% accurate. you will need to test this yourselves and see if it works. let me know how you get on. Link to comment https://forums.phpfreaks.com/topic/137585-multiple-sessions-or-somethign-to-the-same-effect-how-can-i-do-it/#findComment-719337 Share on other sites More sharing options...
MadnessRed Posted December 20, 2008 Author Share Posted December 20, 2008 php ian thats exatcly what I want my page has a template engine, so what I did was rather than "echo $page;" I did echo sortlink($page); I then in sortlinks did an ireplace to change "./?page=" to "./?session=".$_GET['session']."&page=" and now it works perfectly. Link to comment https://forums.phpfreaks.com/topic/137585-multiple-sessions-or-somethign-to-the-same-effect-how-can-i-do-it/#findComment-720406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.