dazman Posted October 20, 2009 Share Posted October 20, 2009 I am not trying to do anything too fancy, I am just trying to get some $_SESSION data to save and use it on the next page, but so far no luck. Its saving some data to $_SESSION['name'] and then loading the header, but that header re-directs using another header command (no whitespace obviously) and then on that page, it has a php include that i need to call the superglobal $_SESSION['name']. At the moment i just want to print the thing, i will deal with functionality once i can actually pass the session data to the next page. Input page has: $sql = "SELECT UID FROM User WHERE Username='$_POST[username]' AND Password='$_POST[password]' AND CID='$_POST[CompanyID]';"; $result = mysql_query($sql); $num = mysql_numrows($result); if ($num == 1) { $sql = "SELECT CompanyName FROM Company WHERE CID ='$_POST[CompanyID]';"; $result2 = mysql_query($sql); $companyname = mysql_result($result2, 0); $id = mysql_fetch_assoc($result); setcookie("nameofcookie", $value, time()+3500); //setcookie("auth", "yes", time()+300); //setcookie("id", $id['id']); //setcookie("username", $id['username']); $successful = "Location: ./".$companyname."/index.php"; session_start(); $_SESSION['name'] = $_POST['CompanyID'].$_POST['username']; //companyID.username is the format for session name. session_write_close(); mysql_close(); header ($successful); //where to go if successful } else { header ('Location: login.php'); // where to if fail } ?> And I am trying to call $_SESSION['name'] on the other page, but the piece of code is inside a small <div> include, loaded by the header page. header page calls this: index.php (which re-directs to) <?php header( 'Location: ./menu/' ) ; ?> <HTML> BLAH BLAH BLAH </head> <body> <?php include '../includes/pageheader.php'; ?> <more html> Here is the contents of that include (pageheader.php). <div id="headerbar"> <a href="index.php"><img alt="Solace Logo" src="../images/solacelogo.jpg" class="solacelogo" /></a> <ul id="toppageoption"> <li><a href="../help.php">Help</a></li> <li><a href="../changecompany.php">Change Company</a></li> <li><a href="../logout.php">Logout (<?php echo $_SESSION['name']; ?>)</a></li> </ul> </div> Link to comment https://forums.phpfreaks.com/topic/178321-solved-session-is-not-saving/ Share on other sites More sharing options...
Alt_F4 Posted October 20, 2009 Share Posted October 20, 2009 have you included session_start(); on the pages that need to set and display the session variable? Link to comment https://forums.phpfreaks.com/topic/178321-solved-session-is-not-saving/#findComment-940291 Share on other sites More sharing options...
dazman Posted October 20, 2009 Author Share Posted October 20, 2009 Thanks heaps bud, I am quite new to sessions... So still learning the in's and outs. I put it before the HTML Doctype in the PHP script. Really appreciate your help. Link to comment https://forums.phpfreaks.com/topic/178321-solved-session-is-not-saving/#findComment-940297 Share on other sites More sharing options...
Alt_F4 Posted October 20, 2009 Share Posted October 20, 2009 no problems Link to comment https://forums.phpfreaks.com/topic/178321-solved-session-is-not-saving/#findComment-940342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.