Re: I'm a newbie and running php on Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks you Nathan.
That worked.
Sincerely,
King

"Nathan Rixham" <nrixham@xxxxxxxxx> wrote in message news:4BB37E7E.5040402@xxxxxxxxxxxx
Ashley Sheridan wrote:
On Wed, 2010-03-31 at 11:32 -0500, King Coffee wrote:

Hi,

I ran the following code snippet on Windows IIS 7, in my index.php file and
it worked fine. But when run it on Linux, the "die" code is executed.

Is there an include file or something else I need to to process this on a
linux server?

<?php
echo '<h1>Redirecting... Please Wait</h1>';
/*
redirect('welcome.html');
*/
if (!headers_sent()) {
header('Location: ' . 'http://auction.househops.com/index.php');
} else {
die('Could not redirect.');
}
?>


Thanks,
King




This should never ever redirect. You've got an echo statement as your
first line of code. Once output has been sent to the browser, PHP cannot
send a redirect header, as the default ones get sent with the output.

problem is very very simple; simply swap the code order

<?php
// add in logic if you want
header('Location: ' . 'http://auction.househops.com/index.php');
echo '<h1>Redirecting... Please Wait</h1>';
?>

but please expand including a link to where you are redirecting too.

The apache default pages are very very good and include the status
(+code) and a short note:
302 Found
The resource you requested has been found <here-link>

note: that's not the exact text, but you get the idea.

I think maybe you'd need a Javascript redirect here, but that comes with
a warning that you cannot rely on everyone to have Javascript available
or enabled on their browser. People do turn it off, people do use
plugins such as NoScript, some routers have been known to strip
Javascript from web pages and not ever browser supports all Javascript
(think text browsers, speech and Braille browsers, etc)

no no no; (sorry ash) but HTTP is there for a reason and it accommodates
everything we need + can be used for *any* file (how do you javascript
redirect an image for instance) - all catered for.

always remember that the web is built on http & hypermedia (media w/
links); it's the whole reason we have a web, is the web and works v well.

also worth noting that apache foundation formed by roy t fielding, same
man who wrote rest, which is the model for http, and check the name at
the top of http, roy again; he's put in tonnes of work and guidance to
the full net, and of course apache http server itself - when in doublt
just copy apache and read the rfc + dissertation.

Why do you need to echo out a message to the user that the browser is
redirecting anyway? A header redirect will be seamless and the user
shouldn't even notice anything happening except for the URL changing.

because user agents MAY redirect, they don't have to - and when its a
post or such like they may want to make the choice of whether to proceed
or not; likewise from https to http and so forth.

http rfc is pretty clear that with every 3xx & 4xx status could you
should give a reason as to why and also give possible actions the user
an take next - preferably as hypermedia links to make it properly resftul.

"307 Temporary redirect, redirecting you to <xxxx> click the link if you
are not automatically redirected".


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux