scottybwoy Posted November 1, 2006 Share Posted November 1, 2006 Hi, I have a login function that goes off anf finds the relative details for logging in and then procedes to open up the session to insert the data. Let me show you what I have :[code]<?php function login() { $this->authorise($this->getUserName()); if ($this->authorise->success = TRUE) { global $username, $user_id, $data; $this->sessCon(); session_start(); $data = $_SESSION["SESSION_USER_ID"]; $qry = mssql_query("SELECT * FROM sessTbl WHERE value LIKE '%" . $data . "%'") or die("Session ID Query Failed"); $username = $this->getUserName(); $user_id = $this->getUserId($username); if (!$row = mssql_fetch_row($qry)) { $_SESSION["SESSION_USER_ID"] = $user_id; $_SESSION["SESSION_USERNAME"] = $username; } } else { die ("Get Out!"); } }?>[/code]I tried using an If (!isset($_SESSION["SESSION_USER_ID"])) But that didn't work it just tried writing the new session data over the top of the existing data, but as am using database storage for it I just got an error of trying to put data in twice.But now all it does is wright the username and ID in, but on refresh it will just make a new session key and not put any data in at all, so it's a bit closer but not what I want.Can anybody help me out on what I can do to make it work, thanks Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted November 1, 2006 Author Share Posted November 1, 2006 Realised that was never going to work as the old data would always be (until carbage collection) there so I changed it back to this :[code]<?php function login() { $this->authorise($this->getUserName()); if ($this->authorise->success = TRUE) { global $username, $user_id; session_start(); if (!isset($_SESSION["SESSION_USER_ID"])) { $_SESSION["SESSION_USER_ID"] = $user_id; $_SESSION["SESSION_USERNAME"] = $username; } } else { die ("Get Out!"); } }?>[/code]But now it still keeps making a new session ID, surely this is a standard procedure script, that many of you already have a good working way round, so please could you share a moment to help me please. This is the second time i've posted on this issue and find it hard getting my head around it :( Quote Link to comment Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 If I understand you correctly, you are saying that the values you assign to session variables are not persistant. You need to register these session variables first, as in the example below. You also need to make sure that you start the session on each page.[code]<?php function login() { $this->authorise($this->getUserName()); if ($this->authorise->success = TRUE) { global $username, $user_id; session_start(); if (!isset($_SESSION["SESSION_USER_ID"])) { session_register('SESSION_USER_ID'); $_SESSION['SESSION_USER_ID'] = $user_id; session_register('USERNAME'); $_SESSION['SESSION_USERNAME'] = $username; } } else { die ("Get Out!"); } }?>[/code] Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted November 2, 2006 Author Share Posted November 2, 2006 I have it solved now, It was how I was calling the function, I changed it to this :[code]<?php global $username; sessCon(); $username = $this->getUserName(); $sql = mssql_query("SELECT * FROM sessTbl WHERE value LIKE '%" . $username . "%'"); if (!$row = mssql_fetch_row($sql)) { $this->login(); }?>[/code]Now it works!! Quote Link to comment 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.