...

View Full Version : Problems with joining web page url and relative paths together



PHP6
12-04-2008, 11:58 PM
Hello,

I have written simple function to join url and relative path together in one url (may be it will be useful):


private function JoinUrlAndPath($url, $path) {
if (substr($path, 0, 7) == 'http://') {
return $path;
} else if (substr($path, 0, 1) == '/') {
if (preg_match('#http://[^/]*#', $url, $match)) {
return $match[0].$path;
}
} else if (substr($path, 0, 2) == '..') {
// remove last slash in the url if such exists
if (substr($url, strlen($url)-1, 1) == '/')
$url = substr($url, 0, strlen($url)-1);
$url = substr($url, 0, strrpos($url, '/'));
if ($url == 'http:/') return false;
$path = substr($path, 3, strlen($path)-3);
return $this->JoinUrlAndPath($url, $path);
} else if (substr($path, 0, 2) == './') {
$path = substr($path, 2, strlen($path)-2);
return $this->JoinUrlAndPath($url, $path);
} else {
$domainPath = substr($url, 0, strrpos($url, '/'));
if ($domainPath == 'http:/') $domainPath = $url;
return $domainPath.'/'.$path;
}
return false;
}

It worked nice until now. Today I was parsing web page with submit form. Lets say submit form had action "index.php/do/login/" and page’s url was "http://example.com/index.php/do/authorize/".

Since the first url was treated as directory (it is ended with slash) the action was just simply appended to the web page's url. I get following: "http://example.com/index.php/do/authorize/index.php/do/login/". BUT it does not work...

I have checked all packages sent from my PC to the server and discover that Firefox sends data to "http://example.com/index.php/do/login/" instead of my url.

The question is: how browser understands that index.php was script and not a directory name? Why it does not append action to the url? What is the standards of parsing relative paths and urls?

Thanks in advance

oesxyl
12-05-2008, 12:23 AM
It worked nice until now. Today I was parsing web page with submit form. Lets say submit form had action "index.php/do/login/" and page’s url was "http://example.com/index.php/do/authorize/".

Since the first url was treated as directory (it is ended with slash) the action was just simply appended to the web page's url. I get following: "http://example.com/index.php/do/authorize/index.php/do/login/". BUT it does not work...

I have checked all packages sent from my PC to the server and discover that Firefox sends data to "http://example.com/index.php/do/login/" instead of my url.

The question is: how browser understands that index.php was script and not a directory name? Why it does not append action to the url? What is the standards of parsing relative paths and urls?

Thanks in advance
If action attribute is like that:


/index.php/do/login/

or relative as in your case, any browser not only firefox will work the way you describe.

use absolute path instead, more exactly generate action attribute with full path as


http://example.com/index.php/do/authorize/index.php/do/login/


best regards

PHP6
12-05-2008, 12:36 AM
If action attribute is like that:

/index.php/do/login/
or relative as in your case, any browser not only firefox will work the way you describe.

use absolute path instead, more exactly generate action attribute with full path as

http://example.com/index.php/do/authorize/index.php/do/login/
best regards
Thanks for your replay. The point is that the action was relative and it was big surprise for me why it did not append action. I have used "Tamper Data" Firefox add-on to check where the data was sent… and it was "http://example.com/index.php/do/login/" instead of "http://example.com/index.php/do/authorize/index.php/do/login/" Ok, I will double check it right now to make sure that I have not missed anything...

oesxyl
12-05-2008, 12:41 AM
Thanks for your replay. The point is that the action was relative and it was big surprise for me why it did not append action. I have used "Tamper Data" Firefox add-on to check where the data was sent… and it was "http://example.com/index.php/do/login/" instead of "http://example.com/index.php/do/authorize/index.php/do/login/" Ok, I will double check it right now to make sure that I have not missed anything...
that have nothing to do with your browser, your server process the form and build, based on what you have in action attribute, the answer.

best regards

PHP6
12-05-2008, 12:50 AM
that have nothing to do with your browser, your server process the form and build, based on what you have in action attribute, the answer.
Right now I have checked on my own server with sample index.php and form with such action. The data was sent to: "http://example.com/index.php/do/authorize/index.php/do/login/" as you said.

I will try to find the web site where I get this error message with submit form. I will double check the action field and the url where the data will be sent after pressing submit button.

p.s. theoretically it could be my own bug, since I am coding almost 14 hours non stop :)

oesxyl
12-05-2008, 12:57 AM
Right now I have checked on my own server with sample index.php and form with such action. The data was sent to: "http://example.com/index.php/do/authorize/index.php/do/login/" as you said.

I will try to find the web site where I get this error message with submit form. I will double check the action field and the url where the data will be sent after pressing submit button.

p.s. theoretically it could be my own bug, since I am coding almost 14 hours non stop :)
could be some old code not upgraded or something else on that server.

rest is part of work, :)
best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum