Re: Forward slashes and header requests

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

 



I had a similar thing happen with a file management system. I found the
best way to fix it was to use

$location = str_replace('//','/', $_SERVER['REQUEST_URI']);

Ash
www.ashleysheridan.co.uk
--- Begin Message ---
PHP List,

I have built my own CMS system, and I've just finished setting it up so that it sends a test cookie to see if the browser has cookies enabled. If it doesn't, it does URL rewriting to handle sessions.

Part of this process involves reloading the page, and sending back a header to get it to go to the right page.

In amongst the code, I have this line:

header ("Location: /$userRequest");

$userRequest can sometimes be empty, such as when someone only types the domain name in their browser's URL field. Like, "http://www.mynicesite.com";.

But, I've learned that if I just do this:

header ("Location: $userRequest");

Then the the browser displays nothing at all. There has to be at least something after "Location: " in the header() command. That's why I put the forward slash in, thinking that it would take people to the root directory of the site.

It works for when people put nothing in the URL other than the domain name. And it works for every other page or directory on the site.

But, I've also learned that if someone creates a link like this:

<a href="/">click here</a>

... then what happens is that the system gets confused about what directory it is in and will lose track of any files located by relative paths. CSS files and images are not found, and the page comes up completely unformatted.

I've done a lot of experimenting, and one thing I tried was this:

$userRequest = trim($_SERVER['REQUEST_URI'], "/");

... so that I would take the slash back out of the URL when it came back. But it still doesn't work, so now I'm wondering if the browser is doing something different when it handles a single forward slash.

Bottom line, I can't figure out why this:

<a href="/">click here</a>

... does not work with this:

$userRequest = trim($_SERVER['REQUEST_URI'], "/");
header ("Location: /$userRequest");

Any suggestions or help would be greatly appreciated.

--
Dave M G

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



--- End Message ---
-- 
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