Zeradin Posted December 18, 2009 Share Posted December 18, 2009 I have this code: if ($password == $login_info['password']) { echo "<strong>Login succeeded!</strong>"; $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; ?><script type="text/javascript"> setTimeout('window.location="index.php?p=update"', 1500) </script><?php echo '<br /> <a href="update.php">click here to continue if you are not redirected</a><br /> <br /><img src="images/loading.gif" alt="loading..." />'; echo $_SESSION['username']; } that verifies login information and then sends it to the update page. the session is still started on the update page and the username session variable works on this page, but is lost on the update page. I don't know why I'm having so much trouble today. Probably something obvious. Please advise. Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/ Share on other sites More sharing options...
wildteen88 Posted December 18, 2009 Share Posted December 18, 2009 Make sure you're calling session_start at the top of any page that uses sessions. Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980188 Share on other sites More sharing options...
Zeradin Posted December 18, 2009 Author Share Posted December 18, 2009 i have session_start() on the index page that loads all the other pages so every page has session start at the beginning of it. Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980189 Share on other sites More sharing options...
wildteen88 Posted December 18, 2009 Share Posted December 18, 2009 Have you place session_start in update.php? Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980191 Share on other sites More sharing options...
Zeradin Posted December 18, 2009 Author Share Posted December 18, 2009 update.php is loaded by index so there's a session start at the beginning of index. If i tried putting a session start in update I'd get an error for headers already sent. Does this have something to do with window.location? Does that get rid of session variables? Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980193 Share on other sites More sharing options...
PFMaBiSmAd Posted December 18, 2009 Share Posted December 18, 2009 How is index.php loading (including) the other pages? Is it using a file system path or a URL in the include statement? Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980194 Share on other sites More sharing options...
Zeradin Posted December 18, 2009 Author Share Posted December 18, 2009 <?php $page = $_GET['p']; ?> then later... if($page != NULL) { include($page.'.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980196 Share on other sites More sharing options...
Zeradin Posted December 18, 2009 Author Share Posted December 18, 2009 It's not the window location, I took it out and I still lost the variables. It's so weird. It echos out correctly and then on the next page it immediately does not echo out. Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980230 Share on other sites More sharing options...
Zeradin Posted December 18, 2009 Author Share Posted December 18, 2009 details: i have a login page that is just a form and a javascript $(document).ready(function() { $("#login_form").submit(function() { var unameval = $("#username").val(); var pwordval = $("#password").val(); $.post("check_login.php", { username: unameval, password: pwordval }, function(data) { $("#status p").html(data); }); return false; }); }); which loads login_check.js that makes the variables. maybe there's someway they aren't actually being read to the session because the javascript is adding it to another page? and also the post variable is in the login_check, not the login? Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980233 Share on other sites More sharing options...
Zeradin Posted December 18, 2009 Author Share Posted December 18, 2009 I think it might be because of this: $("#status p").html(data); outputs the html of check_login but not the php variables? is there something similar that'll pass variables too? Quote Link to comment https://forums.phpfreaks.com/topic/185626-session-woes/#findComment-980264 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.