开发者

Safari 5.1 in doesn't allow <video> source to detect $_SESSION variables

I have a download.php script that detects if a user is logged in with a $_SESSION variable, and reads out a video file to the user. If I call this from a element in Safari 5.0.5, the script detects the session variable and works as expected. In 5.1 the session variables are NOT read by the download.php and it acts like the user isn't logged in. If I call the script directly from the address bar, it works fine. If I call from my iPhone, it is detected as well. Does anyone know if this is a bug or if there's a work-around? I would have to re-write a lot to try and not use sessions. Thanks.

Here's a troubleshooting script. This shows the correct session data:

<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Test</title> 
    </head>
    <body>
        <video width="640" height="480" controls="true" autoplay="false" id="v">
            <source src="video.php" type="video/mp4" />
        </video>
        <?php
        echo "<pre>";
        var_dump($_SESSION);
        echo "</pre>";
        ?>
    </body>
</html>

This writes 'Session Not Detected' every time I load the above page, but the session is detected with Safari 5.0.5 and iOS:

<?php
session_start();

// write local error log
function write_log($txt) {
    $myFile = 'error.log';
    $fh = fopen($myFile, 'a') or die("can't open file");
    fwrite($fh, "$txt\n");
    fclose($fh);
}

if ($_SESSION) {
    write_log(date('Y-m-d H:i:s'). ' Session Detected');
} else {
    write_log(date('Y-m-d H:i:s'). ' Session Not Detected');
}

?>

EDIT: Safar开发者_StackOverflowi Inspector shows the status of calling video.php as 'pending', and has no headers other than the request url. Fixed the session_start, but still works the same.

EDIT: Okay if I read the SERVER variables, the difference between 5.1 and 5.0.5 is that 5.0.5 has: HTTP_CONNECTION => close, and HTTP_COOKIE contains a PHPSESSID

EDIT: I ran Safari in 32 bit mode and it worked again...


If cookies aren't automatically passed to the script called by a <video> element, you could just pass the PHPSESSID as a GET parameter so on the page where the video is embedded, you put something like:

<video ...>
    <source src="video.php?PHPSESSID=<?php echo session_id(); ?>" type="video/mp4" />
</video>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜