[email protected] Posted July 13, 2010 Share Posted July 13, 2010 Hi all. Please help if you can. I'm trying to build a site that runs without page reloads. Navigation is achieved via sliding pages (Jquery) in and out. I am having trouble with carrying the users ID across the various sliding pages. I've read many forums on this, with many different!! solutions, but after several hours can't get any to work, hence a new post. I start with a session_start() of course and then populate a couple of session variables from the database. $_SESSION['usr']=$row['usr']; $_SESSION['id'] = $row['id']; These can be used in the first page no problem. All good so far. I then want to slide a different page in using jquery and somehow carry the session variables over. By default, they are lost because I am assuming the new slid in PHP page is run after the initial load. Here's the JS code to slide the new page in. It uses the ID of the <div> to pass a variable to PHP to populate the second page. That all works fine. $(".scrollclick").click(function () { var show = this.getAttribute("id"); $("#hallacontent").load("showhall.php?show="+ show); $("#homepagecontent").hide("slide", { direction: "left" }, 1000); $("#hallacontent").css("visibility","visible"); $("#hallacontent").show("slide", { direction: "right" }, 1000); I've got a session_start() at the top of the target page, but it won't hold the original session variables. It's is holding other session variables generated on that page though so it's kind of working!! So having read all the other threads I can, it seems clear that I need to pass the "usr" variable in the PHP url somehow, but I am really struggling with syntax. I've seen answers that suggest I can convert the PHP session var into a javascript var, as here: var usr = <?php echo $_SESSION['usr']; ?> and I'd obviously be able to use that JS variable to _get it back to PHP. I've seen several different variations on this theme, none of which seem to work. So that's it, can someone help with either a simple fix to add to the URL to pass the "usr" to the other page, or potentially tell me I'm on the wrong track and there's a better way to do it. Many thanks: currently very frustrated!!! TonyJ Link to comment https://forums.phpfreaks.com/topic/207639-php-sessions-and-javascript/ Share on other sites More sharing options...
kenrbnsn Posted July 13, 2010 Share Posted July 13, 2010 You have to use session_start() in all PHP scripts that are initiated via the AJAX functions. Ken Link to comment https://forums.phpfreaks.com/topic/207639-php-sessions-and-javascript/#findComment-1085498 Share on other sites More sharing options...
[email protected] Posted July 13, 2010 Author Share Posted July 13, 2010 Thanks, yes I may not have made that clear in my post but I have session_start() at the top of every PHP page as as I said, I have confirmed that it is holding other session values generated directly on that page. It's running under a v4 PHP if that makes any difference. Haven't braved upgrading to V5 in case it breaks something. Link to comment https://forums.phpfreaks.com/topic/207639-php-sessions-and-javascript/#findComment-1085499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.