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 4249690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:25:48+00:00 2026-05-21T04:25:48+00:00

I want to have a comet-like iframe on my page, but when the session

  • 0

I want to have a comet-like iframe on my page, but when the session changes the info in the iframe does not and i did a dump of the $_SESSION variable in the iframe and it was not changing.

My question is, how do i update the $_SESSION variable in the comet iframe when the client $_SESSION changes?

Thanks so much ^_^

update with code:

client:

<?php
    session_start();
    if(!isset($_SESSION['count'])) $_SESSION['count'] = 0;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Test Comet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type='text/javascript' src='../js/jquery.js'></script>
    <script type="text/javascript">
        function test_function(msg){

            $('p').html(msg)

        }

        $('div').click(clickMe);

        function clickMe(event){
            $.ajax({
                url: 'addSess.php'
            })
        }
    </script>
  </head>
  <body>
      <p>This is a test</p>
      <div>click me</div>
    <iframe src="output.php" width="0" height="0" style="display: none;"></iframe>
  </body>
</html>

comet iframe (output.php):

<?php
session_start();
ob_start();
echo 'hello';
flush_buffers();
while(true){

    echo "<script>window.parent.test_function('".time().' session: '.$_SESSION['count']."');</script>";

    flush_buffers();

    sleep(1);


}

function flush_buffers(){
    ob_end_flush();
    ob_flush();
    flush();
    ob_start();
}
?>

addSess.php:

<?php
session_start();

if(!isset($_SESSION['count'])) $_SESSION['count'] = 0;
$_SESSION['count']++;


echo $_SESSION['count'];
?>

also another thing i noticed is that its freezing up the browser from going to my site, as soon as i close the client, everything else loads

  • 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-21T04:25:49+00:00Added an answer on May 21, 2026 at 4:25 am

    As long as you make changes to the $_SESSION, all reloads to the iframe that does var_dump($_SESSION); should see the new session. Are you properly using session_start()?

    Update with some code please and we’ll see how we can help.

    UPDATE

    First off, your comet page needs set_time_limit(0); so it runs indefinitely (the connection can still get cut off and you’d need to do something to restart the comet connection)

    Second off, output buffering might be giving you errors, PHP is wonky in that sense, my local test doesn’t work with your code because of it. If I add the line:

    <iframe src="output.php" width="0" height="0" style="display: none;" onload="alert('Iframe Loaded');"></iframe>
    

    I get the alert at the same time as the update to the main page, meaning flush buffers failed to actually flush buffers. I’ll return when I get the code working here.

    UPDATE2

    Sigh. Simplicity…

    $('div').click(clickMe);
    

    Needs to be called after the HTML DOM loads. try:

    $(function(){
        $('div').click(clickMe);
    });
    

    Also you should consider changing your comet code to this:

    <?php
    session_start();
    ob_implicit_flush(true);
    ob_end_flush();
    echo 'hello';
    while(true){
        echo "<script>window.parent.test_function('".time().' session: '.$_SESSION['count']."');</script>";
        sleep(1);
    }
    ?> 
    

    By doing ob_implicit_flush you don’t need to call flush_buffers constantly. You also need ob_end_flush to cancel output buffering.

    You should also take note that session_destroy is needed. Otherwise your site waits for the comet session to close before it can start a new session.

    The way session_start() actually works, is it waits for the session to become available. This means you need to use session_id to generate a different session for your comet or use files… or employ some other technique.

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

Sidebar

Related Questions

I want to access camera to record video to upload, but have come across
I need something like a cookie, but I specifically don't want it going back
I have what seems like it should be a really simple problem, but somehow
I have a string with multiple sequences of consecutive characters like: aaabbcccdddd I want
I want to come up with a language syntax. I have read a bit
I want that the menu i have created for testing entries should come in
i want have an image and i want to set it as a background
I have a UITextView and I want have two buttons. When the user taps
I try to read out all existing calendars. I want have a HashMap with
want to have a Hyperlink-Button in a gridView in which I can display a

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.