daneth1712 Posted July 26, 2009 Share Posted July 26, 2009 Hi, Would anyone be able to tell me or advise me on how or if it is possible to take more than 1 variable in a script and add it to a session? I need to be able to take 3 variables from a script and add them to a session so I can check them off against another form on the next page. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/167531-sessions-and-variables/ Share on other sites More sharing options...
lynxus Posted July 26, 2009 Share Posted July 26, 2009 <?php session_start(); $_SESSION['username'] = $_POST['username']; $_SESSION['foo'] = $_POST['foo']; $_SESSION['bar'] = $_POST['bar']; $_SESSION['anotherVAR'] = "someDATA"; echo $_SESSION['bar']; ?> Link to comment https://forums.phpfreaks.com/topic/167531-sessions-and-variables/#findComment-883435 Share on other sites More sharing options...
daneth1712 Posted July 26, 2009 Author Share Posted July 26, 2009 Hi lynxus, Thanks for your reply. I think I know where I am going wrong here, I just dont know how to fix it. Basically, I have a 3 field form that gets sent to the below page: <?php $name=($_POST['name']); $email=($_POST['email']); $country=($_POST['country']); //send back to the activate page if called from other location or empty if (!isset($name) || !isset($email) || !isset($country)){ header( "Location: activate.html" ); } elseif (empty($name) || empty($email) || empty($country)) { header( "Location: activate.html" ); } include 'includes/config.php'; $connection = @mysql_connect($hostname, $adminuser, $adminpass) or die(mysql_error()); $dbs = @mysql_select_db($database, $connection) or die(mysql_error()); $sql = "SELECT * FROM userinfo WHERE name='$name' AND email_address='$email' AND country='$country'"; $result = @mysql_query($sql,$connection) or die(mysql_error()); $row = mysql_fetch_object($sql); if ($result) { while ($array= mysql_fetch_assoc($result)) { session_start(); session_register('name', 'email', 'country'); header( "Location: activate_part2.php" ); } } else { echo 'No results found.';} ?> Now I am either going wrong with setting the sessions above, or in the 'start session' which is added at the top of each of the pages in the form.... <?php //start the session session_start(); $_SESSION['name'] = $_POST['name']; $_SESSION['email'] = $_POST['email']; $_SESSION['country'] = $_POST['country']; if(session_is_registered('name', 'email', 'country')){ $name_id=$_SESSION['name']; $email_id=$_SESSION['email']; $country_id=$_SESSION['country']; } else{ //the session variable isn't registered, send them back to the activate page header( "Location: activate.html" ); } ?> I am getting redirected back to the activate.html page so I know the problem is how I have set the sessions. Any pointers would be really helpful. Thanks again! Link to comment https://forums.phpfreaks.com/topic/167531-sessions-and-variables/#findComment-883451 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Don't use session_is_registered(), it is deprecated. Use isset($_SESSION['name']) instead. Also, session_is_registered does not accept anything else but a single string. Check the PHP documentation before using functions that you are uncertain of. Link to comment https://forums.phpfreaks.com/topic/167531-sessions-and-variables/#findComment-883494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.