Drezard Posted December 9, 2006 Share Posted December 9, 2006 Hello, Heres my class with all my functions:[CODE]<?phpsession_start();error_reporting(E_ALL);class web { var $connection = NULL; var $login = NULL; var $dbhost = "localhost"; var $dbuser = "test"; var $dbpass = "test"; var $db = "sellyourownhome"; function connect() { $this->connection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass) or die ("Unable to connect!"); mysql_select_db($this->db) or die ("Unable to select database!"); } function close_connect() { mysql_close($this->connection); } function check_user() { if (!isset($_SESSION['userinfo'])) { $this->login_box(); } if (isset($_SESSION['userinfo'])) { $this->connect(); $userinformation = explode(" ", $_SESSION['userinfo']); $user = $userinformation[0]; $pass = $userinformation[1]; echo $user; echo $pass; $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { $this->login = 1; } if ($count == 0) { echo "ERROR: Session has corrupted. Please logout and relogin"; $this->login = 0; } } } function add_user() { if (isset($SESSION['userinfo'])) { $this->check_user(); } if (!isset($_SESSION['userinfo'])) { $this->connect(); if (!isset($_POST['user'])) { echo "<form action='' method='post'> Username: <input type='text' name='user'> Password: <input type='password' name='pass'> Comfirm Password: <input type='password' name='pass2'> Email: <input type='text' name='email'> Comfirm Email: <input type='text' name='email2'> <input type='submit' name='submit'> </form>"; } if (isset($_POST['user'])) { $user = $_POST['user']; $pass = $_POST['pass']; $pass2 = $_POST['pass2']; $email = $_POST['email']; $email2 = $_POST['email2']; $priv = $_POST['priv']; if ($pass == $pass2) { if ($email == $email2) { $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { echo "Username already created"; } if ($count == 0) { $query = "INSERT INTO users (user, pass, priv) VALUES ('$user', '$pass', '2')"; $result = mysql_query($query) or die ("Error in query: $query."); $query = "INSERT INTO profiles (user, email) VALUES ('$user', '$email')"; $result = mysql_query($query) or die ("Error in query: $query."); echo "Acount sucessfully created"; } } else { echo "Emails dont match"; } } else { echo "Passwords dont match"; } } } } function login_box() { $this->connect(); if (isset($_SESSION['userinfo'])) { $this->check_user(); $userinformation = explode(" ", $_SESSION['userinfo']); $user = $userinformation[0]; echo 'Welcome, $user'; } if (!isset($_SESSION['userinfo']) && !isset($_POST['user'])) { echo "<form action='' method='post'> Username: <input type='text' name='user'> Password: <input type='password' name='pass'> <input type='submit' name='submit'> </form>"; } if (!isset($_SESSION['userinfo']) && isset($_POST['user'])) { $user = $_POST['user']; $pass = $_POST['pass']; $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { $_SESSION['userinfo'] = '$user $pass'; echo "Sucessfully logged in"; } if ($count == 0) { echo "Username or password are incorrect."; } } } function logout() { if (!isset($_SESSION['userinfo'])) { echo "You have to be logged in to view this."; } if (isset($_SESSION['userinfo'])) { session_destroy(); echo "You have sucessfully logged out"; } } }?>[/CODE]Alright so with the function check_user(); it doesnt explode the session properly. The variables $user and $pass are empty. Whats wrong with it?The whole code is there so you should be able to see that the function login_box sets the session and i want check_user to read it but it doesnt.- Cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/30018-explode-problem-solved/ Share on other sites More sharing options...
esukf Posted December 9, 2006 Share Posted December 9, 2006 Try changing the line $_SESSION['userinfo'] = '$user $pass';to $_SESSION['userinfo'] = "$user $pass"; //use double quotes instead of single Link to comment https://forums.phpfreaks.com/topic/30018-explode-problem-solved/#findComment-138020 Share on other sites More sharing options...
sylesia Posted December 9, 2006 Share Posted December 9, 2006 A few things to try, first off, I am pretty sure if you do it the way you are, you need it to look like$_SESSION['userinfo'] = $user . " " . $pass; // Took out quotes and added a period which binds them together with the spaceCould have two variables if that does not work, a user and pass variableTell me what happens if you do the period one though, that should help you in what you need Link to comment https://forums.phpfreaks.com/topic/30018-explode-problem-solved/#findComment-138140 Share on other sites More sharing options...
kenrbnsn Posted December 9, 2006 Share Posted December 9, 2006 The code[code]<?php$some_var = "$var1 $var2";?>[/code]and the code[code]<?php$some_var = $var1 . ' ' . $var2;?>[/code]produce the same result. Try it yourself.Ken Link to comment https://forums.phpfreaks.com/topic/30018-explode-problem-solved/#findComment-138148 Share on other sites More sharing options...
Drezard Posted December 10, 2006 Author Share Posted December 10, 2006 The double quotes worked. Thanks for the help.- Cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/30018-explode-problem-solved/#findComment-138317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.