php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22671 IMG SRC not able to get SESSION values
Submitted: 2003-03-13 01:31 UTC Modified: 2003-03-14 01:04 UTC
From: ronneil at restricted dot dyndns dot org Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.0 OS: FreeBSD 4.7 and Redhat 7.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ronneil at restricted dot dyndns dot org
New email:
PHP Version: OS:

 

 [2003-03-13 01:31 UTC] ronneil at restricted dot dyndns dot org
I am trying to retrieve values from a SESSION variable array. To retrieve, I am using <img src=somefile.php>. Unfortunately, I am not able to see any value. Below are 2 sample php files to recreate the error. "test1.php" calls "test2.php" via <img src> TAG.

Currently in production, I have a working code (http://restricted.dyndns.org/codes/ocishow1.php) that uses almost same concept below but this one saves the data to a file first. This code calls another php file (http://restricted.dyndns.org/codes/ocishow2.php) to generate the graph and is called via <img src>.

--------------TEST CODE-------------------
FILENAME : test1.php
<?php
   session_start();
   $time_VAR = array(2343,3234,457,2356,6798,3467,34667,4578,2523);

   for ($ipage=0;$ipage<4;$ipage++) {
       for ($i=0;$i<count($time_VAR);$i++) {
           $_SESSION[$ipage][] = $time_VAR[$i];
       }

    // the following loop verifies if SESSION variable was populated
       for ($i=0;$i<count($_SESSION[$ipage]);$i++) {
           echo "$i.) ".$_SESSION[$ipage][$i]."<br>";
       }
       $pagenum = $ipage;
       $arraysize = count($_SESSION[$ipage]);
       echo "Pagenum : $pagenum, Size of current array : $arraysize<br>";
       echo '<img src="test2.php?count='.$pagenum.'&varsize='.$arraysize.'">';
       echo "New line<br><br>";
   }
   session_destroy();
?>
-------------------------------------------------
FILENAME : test2.php
<?php
    session_start();
    $index = $_GET[count];
    $arraysize = $_GET[varsize];

    // file handling was written to verify the size of array and index if there are really values on it
    $fp1 = fopen("/tmp/checkval.txt","w");
    $err = fwrite($fp1,"Pagenum : $index, Size of Array: $arraysize\n");
    fclose($fp1);
    
    for ($i=0;$i<$arraysize;$i++) {
        $atemp_alltel_VAR[] = $_SESSION[$index][$i];
    }
    // This is the only way I can verify 
    $fp = fopen("/tmp/testing","w");
    for ($i=0;$i<count($atemp_alltel_VAR);$i++) {
        $err = fwrite($fp, $atemp_alltel_VAR[$i]);
    }
    fclose($fp);
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-13 01:36 UTC] rasmus@php.net
You explicitly destroy the session right there at the bottom of test1.php.  Why do you think that the session will still be around by the time the request for the test2 image comes through?  Chances are that test1 has finished executing by then and thus you session data has been destroyed.
 [2003-03-13 16:59 UTC] ronneil at restricted dot dyndns dot org
I have tried the same code and followed what you told me. I have removed the session_destroy() and still, I am not able to extract any values from the session variables. I have noticed that it works when I used include("test2.php"). But I can't used this function since the real code that I have does generate real image.

You should try the code and you will see what I mean.

Thanks. I will wait for another response.
 [2003-03-14 01:04 UTC] rasmus@php.net
Well, sometimes the session data may not have been written by the time the second request comes in.  You need to take care of race conditions.  In cases like these you need to populate your session, then call session_write_close() before you generate those img src links.  Getting session data from an img src triggered PHP script works just fine.  I do it all the time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 03 05:01:29 2024 UTC