php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19991 header() vs. session_register()
Submitted: 2002-10-19 11:04 UTC Modified: 2002-10-24 22:13 UTC
From: ipa4-2001 at lycos dot com Assigned:
Status: Not a bug Package: HTTP related
PHP Version: 4.2.1. OS: Windows 98SE
Private report: No CVE-ID: None
 [2002-10-19 11:04 UTC] ipa4-2001 at lycos dot com
I want to make the use of session in PHP (4.2.1) so I try this code...

session_start();
$_SESSION['user'] = 'myname';
$_SESSION['password'] = 'mypassword';

which is similar to the following...

$user = 'myname';
$password = 'mypassword';

session_start();
session_register('user');
session_register('password');

The problem comes when I add header() function so that the script become...

session_start();
$_SESSION['user'] = 'myname';
$_SESSION['password'] = 'mypassword';
header('Location: http://www.mysite.info/member/index.php');

When I try this (on IE 5.5, Windows 98SE; Apache 1.3.26), it didn't take me to the page I specified above. It led to an error message "The requested URL could not be retrieved".

I don't meet any solution of that so I think it's a bug. Can anyone help me explaining what's going on?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-19 11:05 UTC] derick@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 [2002-10-21 11:15 UTC] jaco at premsoft dot co dot za
Hi,

I also experience this problem.

I am running PHP 4.2.3 on FreeBSD 4.7-PRERELEASE, with Apache 1.3.27. I have tested this with IE 6.0.2600.0000, running on Windows 2000 server SP2.

The following code works for me:

<?php
$dlfile = "./temp.zip";
header("Content-Type: application/download-script-by-hex\n");
header("Content-Disposition: attachment; filename=\"$dlfile\"");
header("Content-Transfer-Encoding: binary");
?>

But, fails as soon as I add session_start().

<?php
session_start();
$dlfile = "./temp.zip";
        header("Content-Type: application/download-script-by-hex\n");
        header("Content-Disposition: attachment; filename=\"$dlfile\"");
        header("Content-Transfer-Encoding: binary");
?>


Also, in lynx (FreeBSD 4.7-PRERELEASE) I can download the file, but, I get a 4 byte Ascii file, the spaces. 

When I remove the session_start(), I get a Ascii file that is 10 bytes bigger than the origional, the new file also filled with spaces.

Am I just missing something here, or is this a bug ?

Thank you.
Regards
Jaco van Tonder
 [2002-10-21 16:43 UTC] hholzgra@php.net
for the original report: you just can't have session stuff
and Location: redirects in the same script, the headers
interfere and confuse browsers ... not a php bug :(

for the latest addition: this is something different,
please verify if it also happens with session.trans_sid=0
in php.ini and create a new report for it
 [2002-10-24 22:13 UTC] ipa4-2001 at lycos dot com
Well, it's OK if it's so, thanks for your information!

But I still didn't get the idea why I can't have session and header Location:in the same script. Does session send such a header Location: too so that the next header Location, which I called after, might confuse the browser?

Thanks for your attention.

Regards,

mahara
 [2002-10-30 11:05 UTC] holmes072000 at charter dot net
I don't think it's a PHP bug. I've added variables to the session and then issued header redirect and haven't had any problems with it on the last couple vesions of PHP. 

As for the second problem, try changing the session.cache-limiter flag in your php.ini. Sessions send a nocache header which will, with IE under SSL, cause the browser to give an error saying it can't locate the file for download. 

---John Holmes...
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 22:01:23 2021 UTC