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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:04:40+00:00 2026-05-25T14:04:40+00:00

I wonder why something like this wouldn’t work (actually doesn’t work): 4.php : <php

  • 0

I wonder why something like this wouldn’t work (actually doesn’t work):

4.php :

<php
session_start();

$my_id = session_id();

$_SESSION['username'] = (($_SESSION['username'] == 'nimic') ? 's-a schimbat' : $_GET['test']);

file_put_contents('comm.g', PHP_EOL.$my_id, FILE_APPEND);

sleep(3); // can be left out

echo $_SESSION['username'];

?>

4.php is a simple page that only sets the "username" component of $_SESSION, then writes the session id to a file, after which it echoes the $_SESSION[‘username’] value.

Then:

3.php :

<php

while(true)
{
    if(file_exists("comm.g"))
    {
        $c = file("comm.g");
        unlink("comm.g");

        session_start();
        foreach($c as $k => $v)
        {
            if($v != '')
            {
                $my_id = session_id();
                session_write_close();
                session_id($v);
                session_start();
                file_put_contents("result.cc", $_SESSION['username'].'---'.$v.'END'.PHP_EOL.PHP_EOL, FILE_APPEND);
                $_SESSION['username'] = 'somethingelse';
                session_id($my_id);
                session_start();
            }
        }
        session_write_close();
    }
}
?>

3.php is run by a cronjob, every minute, for about 30 seconds (until server kills it). Anyway in result.cc I find (in those 30 available seconds) the expected result… the value of $_GET[‘test’].

But it does not modify the value of $_SESSION[‘username’], I didn’t even expect such a behavior actually, I knew that sleep wouldn’t be enough, but still, on a refresh shouldn’t it be modified?…

I know that my code is awful, it is just a test, if it works it would be improved.

But I don’t seem to figure it out. What am I doing wrong?
Actually I am doing a lot of things wrong, the system itself should not be used like this, I know that too, but still, right now this is my only option. I have more complicated ideas about this thing, but if this won’t work, the others won’t work either.

My intention actually is to execute code in separate thread so that I can escape some changes (like registering a wrapper for the file scheme, and having no power to unregister (restore) it when I need to, inside the wrapper class that is) that I made there. Unorthodox method, I know…

So, can you help with any ideas? Thank you.

EDIT 1

Even if lead me to an interesting idea @Ben’s answer wasn’t exact… Actually in cookies is kept only the session id, I replaced the need for cookies by using a file, so that the cronjob knew what session should be modified, I got the correct value for $_SESSION[‘username’] for any "registred" sessions, but even so, I was unable to modify the damn values, it was like they were marked readonly. Now, reconsidering, I found the idea still on it’s feet, being viable, and a solution whatsoever.
So my questions still is up… WHY wouldn’t it work?

  • 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-25T14:04:41+00:00Added an answer on May 25, 2026 at 2:04 pm

    Here’s your problem: 3.php is run by a cronjob.

    The session requires cookies, which requires a web browser and browser state. If you run the script as a cron job, there is no session.

    A solution to your actual problem that you might want to consider is Runkit Sandbox: http://php.net/manual/en/runkit.sandbox.php

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

Sidebar

Related Questions

I wonder if something like this is possible in PHP $goto = 'end'; goto
I wonder how to get something like this: Write copy(a, b, 2, 3) And
I wonder if there's any way something like this would be possible for value
I always wonder if it's correct to say that something like THIS is a
I have something like this $.ajaxSetup({ cache: false }); I am wonder can you
I wonder if there is something like a standalone version of Visual Studio's "Immediate
In an class header I have seen something like this: enum { kAudioSessionProperty_PreferredHardwareSampleRate =
Good Evening, I'm building a website which will will look something like this: So
Lets say that I have got a vector like this. std::vector<a_complicated_whatever_identifier *> *something =
i wonder if there is something similar to Sql Profiler for Sql Server Compact

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.