php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27587 header() works, but not with variables, after a POST request
Submitted: 2004-03-13 12:46 UTC Modified: 2004-03-13 13:14 UTC
From: webmaster at digitalanime dot nl Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.4 OS: Linux
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: webmaster at digitalanime dot nl
New email:
PHP Version: OS:

 

 [2004-03-13 12:46 UTC] webmaster at digitalanime dot nl
Description:
------------
Hello there..

I've been fighting with this code for about a day or two, but it just doesn't seem to work..

If I use output buffering, post a form and want to do a header(), it works.... Only it doesn't when I want to use $_SERVER['REQUEST_URI']..

Reproduce code:
---------------
<?php
ob_start(); // start the outputbuffer
if(!empty($_POST) && !isset($_SESSION['form'])) { // my POST is full, but we can't find a session variable... Strange.. There's someone fucking with my site
 header('location: ' . $_SERVER['REQUEST_URI']);
}
if(empty($_POST)) { // POST is empty... Let's show a form here:
 // do my form here + make a session for the form
}
else { // POST is NOT empty... Let's handle the data
 // handle my data here
}
if(!empty($_POST) && isset($_SESSION['form'])) { // my POST is full, and the session exists.. Fine, let's unset() it. :)
 unset($_SESSION['form']); // unsetting the session..
}
ob_end_flush();
?>

Expected result:
----------------
Well, the first thing I wanted to see, is that the form shows up (yes, it really does, so that's not wrong..)

After that, I'll fill it in and submit it..

I get my data and so.. But, if I refresh, the browser asks me if I want to send the data again.... I click yes, and my code works, except for the header().

If I put header('location: index.php'); in it, It works, but not with $_SERVER['REQUEST_URI'].

EVERYTHING works, except for REQUEST_URI, QUERY_STRING and any of the GET variables..

Actual result:
--------------
A whole blank page..

With about:blank in the title bar..

Al that, nothing more, nothing less.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-13 12:50 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

You're abusing the header function, "Location" must be a capital "L" and you are required to specify the FULL URI:
http://server.example.com/filename.php
 [2004-03-13 13:01 UTC] webmaster at digitalanime dot nl
Yes, I already tried that several times... But without result.

header('Location: index.php');
Works.

header('Location: ' . $_SERVER['PHP_SELF']);
Doesn't work.

And so with this one:

header('Location: http://www.digitalanime.nl/index.php?p=beep
Works.

header('Location: http://www.digitalanime.nl' . $_SERVER['REQUEST_URI']);
Doesn't work.
header('Location: http://www.digitalanime.nl/' . $_SERVER['REQUEST_URI']);
Doesn't work.

In all examples with Doesn't work, I get the same result, a blank page.
 [2004-03-13 13:08 UTC] derick@php.net
Perhaps the variables are just empty? Anyway, this works fine using those variables unless they are not set, please use the php-general@lists.php.net mailinglist for support questions.
 [2004-03-13 13:11 UTC] webmaster at digitalanime dot nl
So... It isn't really a bug?

Well, then I'll going to waste my time on finding more solutions for my 'problem'. :)

Well, I would like to thank you for the support you offered and the time you've taken to try to help me. :)
 [2004-03-13 13:14 UTC] webmaster at digitalanime dot nl
Ehm.. Sorry for double-blasting your database, but I wanted to say that the variables aren't empty.

All values come through clearly and everything works.

If I do this:

<?php
ob_start();
// my stuff (only that form thingie, which is above here..
echo $_SERVER['REQUEST_URI'];
header('Location: http://www.digitalanime.nl' . $_SERVER['REQUEST_URI']);
// my stuff..
ob_end_flush();
?>

I get this on my screen:
/index.php?p=beep

And about:blank in the title bar..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 10:01:31 2024 UTC