Backslash - Forwardslash Issue

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Backslash - Forwardslash Issue

Post by grasshopper »

Recently I moved an intranet site from a Linux box to a Windows Server 2003. The setup is:
Apache 2.0.47
PHP 4.3.10
PostgreSQL 8.0

The main page (index.php) for the site comes up fine. I put in my user id and password and hit login. This should throw me to another page, but instead I get a pop-up error stating that "myserver.com\page_I_want.php could not be found. Please check the name and try again."

The page exists, and here is the kicker - this all works with IE 6, and will not work with Firefox 1.0.

I did notice that the error states mysite.com\page.php - the slash is in the wrong direction. Should be / and not \.

I figure it has something to do with the way Windows does paths. This site worked fine on the Linux box and none of the php code has changed.

Can someone shed some light on how to fix this. I've been over the php.ini and httpd.conf number of times and I can't see anything wrong. I know PHP itself works and loads all the mofules I want.

Please help!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post some of this index.php's code involving the form.
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Post by grasshopper »

I'm pretty sure it's not the code, but if you want to see it, here it is. The index.php is not the file that does the redirection. It only serves as a starting point, get's the user's id and password and passes that info via $_POST variables to a login.php which inturn does the redirection to a different page - the page that will not show. Here's a snippet of code that does the redirection:

Code: Select all

if ($redirect != '') {
        $relative_uri = ltrim($redirect, '/');
      } else if ($_SESSIONї'_usertype'] == 'Client') {
        $relative_uri = 'myissues.php';
      } else if ($_SESSIONї'_usertype'] == 'Root') {
        $relative_uri = 'domains.php';
      } else {
        $relative_uri = 'unassignedissues.php';
      }

      $dirname = dirname($_SERVERї'PHP_SELF']);
      $https = 'http'.($_SERVERї'HTTPS'] ? 's' : '');
      $headertext = "Location: $https://".$_SERVERї'HTTP_HOST'].$dirname.(strrpos($dirname,'/')==(strlen($dirname)-1)?'':'/').$relative_uri;
Again, all of this stuff works if I'm using Internet Explorer, but stops to work if I use Firefox.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might need to have a look at it through the souce browser I posted for Heavy a short time ago... to see the exact headers being sent to the browser(s)
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Post by grasshopper »

feyd wrote:might need to have a look at it through the souce browser I posted for Heavy a short time ago... to see the exact headers being sent to the browser(s)
Found your source browser. Had to modify my php.ini but it works now. What exactly am I looking for?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you switch login.php to use $_REQUEST (for this debugging only) then passing in the username and password to use via the url (get request) the script will show you the headers the script is sending back to the browser. .. just in case some of the code is odd..

I'd guess that $dirname is funky.
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Post by grasshopper »

feyd wrote:if you switch login.php to use $_REQUEST (for this debugging only) then passing in the username and password to use via the url (get request) the script will show you the headers the script is sending back to the browser. .. just in case some of the code is odd..

I'd guess that $dirname is funky.
I'm not entirely sure how to do this. What I have done is used your script and punched in the location of the login.php page in the "get" dialog box and it comes back with header and HTML info, but nothing about variables passed. I don't think I'm doing this right.
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Post by grasshopper »

feyd you are right in assuming that
I'd guess that $dirname is funky.
I used this little bit of code in my login.php to see what it sees:

Code: Select all

$dirname1 = dirname($_SERVERї'PHP_SELF']);
and then I made it print out on the screen the value of $dirname1 and it came back as \. Then I made sure that the $_SERVER['PHP_SELF'] evaluates properly and it did - returned "/login.php". I also tried this:

Code: Select all

$dirname1 = dirname('c:/');
to see if it returns the correct string - should be "c:" but instead I got "c:\"

Seems that when dirname() evaluates the string "/login.php" it does the job half right - it evaluates the path (droping the filename), but then it inverts the slash! Any ideas what's wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

dirname() and it's related functions use file system functions, typically, to determine location information, as they are for the file system, not for web files. So it is functioning correctly.
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Post by grasshopper »

feyd wrote:dirname() and it's related functions use file system functions, typically, to determine location information, as they are for the file system, not for web files. So it is functioning correctly.
So how do I fix this. If I run dirname("/path") it returns "" instead of "/"

I guess my php scripts depend on the value it returns for redirection purposes, and since a "" is returned, a redirection is formed as such:

myserver.com\somefile.php instead of myserver.com/somefile.php

Mozilla Firefox can't deal with that but IE can. Since I'm using Firefox all the time I'd like this to work.

Can anyone help?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's wrong with parse_url() or other related functions?
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post by thegreatone2176 »

a sort of lame way to fix it would be

$string = str_replace("/","\",$string);
grasshopper
Forum Newbie
Posts: 7
Joined: Thu Feb 03, 2005 9:55 am

Post by grasshopper »

thegreatone2176 wrote:a sort of lame way to fix it would be

$string = str_replace("/","",$string);
Thanks! I wasn't looking for a pretty solution, and this did the trick! Although I had to change the mixed search and mixed replace strings to the proper slashes i.e.

Code: Select all

$string = str_replace("&quote;,"/",$otherstring);
Thanks a lot though. It now works in both FF and IE.
Post Reply