Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 914027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:39:10+00:00 2026-05-15T17:39:10+00:00

I’m trying to build a site that runs without refreshes, using Jquery and PHP

  • 0

I’m trying to build a site that runs without refreshes, using Jquery and PHP to populate divs that slide in/out. basics work OK, but I am having trouble passing session values around.

I have a login panel first that captures “$user” in PHP and then stores is as a session variable $_SESSION[‘user’].

I can then use it on the first page OK (the first page gets written by index.php.)
Subsequent pages are called by Jquery, like:

$(".scrollclick").click(function () {
var show = this.getAttribute("id");
$("#page2content").load("showpage2.php?show="+ show);
$("#homepagecontent").hide("slide", { direction: "left" }, 1000);
$("#page2content").css("visibility","visible");           
$("#page2content").show("slide", { direction: "right" }, 1000); 

where the variable “show” comes from a clickable div image name. Again all works fine.

However, the problem is that somehow the session variables are not the same in the other PHP page’s that get loaded, after the initial home page load.

I know to use session_start(); at the top of each PHP script and I’ve echo’ed the session_id() to prove that sessions are working and that strangely the session ids are different.

I’ve even got other scripts populating the session variables quite happily in the other scripts.

I seem to have proved that every other PHP script on the site creates pages with the SAME session id, except the home page which holds a different one. Trouble is, that it’s the home page session that holds the “user” variable that I want to propagate.

I’ve tested it in Chrome, IE and FF. All the same. Result is two session id’s – one for the home page and one for all the others.

I am guessing that there’s something in one of the other pages that is somehow flushing the session, like session_write_close() but I can’t find it. I’ve created the site using a couple of ready made (great) scripts (Jquery chat, tutorialzine login demo), so they might be playing around.

I have just today set up a couple of dummy pages that do roughly the same thing and they work OK, so there HAS to be a really dumb mistake somewhere!!!

Possible workaround?

I even tried finding a way to manually propagate the userid across the PHP calls, but struggled to get the variables into Javascript (for the jquery calls) [I can get this to work OK] and then back into the PHP?user=xxxx string so that I can _GET it back at the other end. [can’t get this to work]

I’ve seen some advice that suggests using:

var username = <?php echo $user;?>;

Some suggest quotes, some don’t. With quotes, it’s just interpreted as a string, without it seems to just stop the javascript dead in its tracks

Does anyone have any pointers to either the sessions issue or the variables workaround ??

The site structure is all flat btw, all (most) in one directory in one domain.

Ever grateful! (as someone who’s now wasted 3 days going round in circles)

TonyJ

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:39:11+00:00Added an answer on May 15, 2026 at 5:39 pm

    PHP’s session implementation relies on a single cookie, my guess is that the browser isn’t passing along the cookie correctly or the response is being cached and reusing a previous session cookie. Try using this to disable caching:

    $.ajax({
        url: "...php",
        cache: false,
        ...
    });
    

    If you haven’t already, watch the AJAX requests with Firebug and check that the session cookies are being sent properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.