Why does sharing PHP sessions between simultaneously open pages seem to work in FF, but not in IE or Chrome?

EDIT I ​​just realized that I must have had a massive brain fart when writing a shortened code sample. You see, I use smarty. So I actually already use the Kips solution, because smarty is displayed after saving the session

I am working on a resource manager implementation (for compacting, compressing and minimizing CSS and JS) for the PHP site I'm working on, and ran into a terribly strange problem. Therefore, when the user navigates to index.php, the files are added to the resource manager object, which combines them into one file and is included in the page through <script src="resource.php?id=123&ext=.js">or<link href="resource.php?id=123&ext=.css" />

Basically, it boils down to the fact that the file path is stored in the session on an accessible page and is read from the session on the resource page. In FF, this works fine. In IE and Chrome, this is not the case.

Here is an example with abbreviated code:

index.php

<?php
session_start();
//Do a ton of stuff
//Including adding several files to the resource object
//Add the resource links to the head
$smarty->append('headSection','<link href="resource.php?id=<?=$resourceID?>&type=.js" />');
</head>
//Save the resource file which:
// - Outputs the file
// - Saves a reference to it in session
$_SESSION[$resourceID] = $file;
//Let Smarty display
$smarty->display($templateFile);
?>

resource.php

<?php
readfile($_SESSION[$_GET['id']] . $_GET['type']);
?>

It seems to me that FF is waiting for a full response to the page before making any new requests to the resources required by this page, while IE and Chrome work by launching a new request, the second of which occurs. In this regard, this error mainly comes down to the condition of the race.

Can anyone confirm that this is really the way it works? And if so, how would I get around him?

+3
source share
2 answers

. , , . , Firefox, IE Chrome, , , . - . index.php :

ob_start('ob_gzhandler');

: a) , , , ; b) gzip.


. . , . index.php, cookie PHPSESSID . .

PHP , . test1.php , 30 , . test2.php ( CSS) . , test2 ( ) .

test1.php

<?php
session_start();
$_SESSION['mycolor'] = 'red';
?>
<html>
<head>
<link rel="stylesheet" href="test2.php" type="text/css" />
</head>
<body>
Starting test...<br/>
<?php
for($i = 0; $i < 6; $i++) //loop will take 30 seconds to complete
{
  echo "$i<br/>\n";
  sleep(5);
}
?>
Done!
</body>
</html>

test2.php

<?php
session_start();
?>
body { color: <?php echo $_SESSION['mycolor']; ?>; }
+1

- , , . , Kip , , , , , ... .

, , , SessionID . , , , , , SessionID (session_regenerate_id()), CSRF. , .

, , ... session_regenerate_id() ?

- : , PHP session_regenerate_id().

: http://www.php.net/manual/en/function.session-regenerate-id.php#81212 .

0

Source: https://habr.com/ru/post/1719543/


All Articles