Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder PHP6's Avatar
    Join Date
    Aug 2008
    Location
    Czech Republic
    Posts
    239
    Thanks
    18
    Thanked 34 Times in 33 Posts

    Problems with joining web page url and relative paths together

    Hello,

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

    PHP Code:
      private function JoinUrlAndPath($url$path) {
        if (
    substr($path07) == 'http://') {
          return 
    $path;
        } else if (
    substr($path01) == '/') {
          if (
    preg_match('#http://[^/]*#'$url$match)) {
            return 
    $match[0].$path;
          }
        } else if (
    substr($path02) == '..') {
          
    // remove last slash in the url if such exists
          
    if (substr($urlstrlen($url)-11) == '/')
            
    $url substr($url0strlen($url)-1);
          
    $url substr($url0strrpos($url'/'));
          if (
    $url == 'http:/') return false;
          
    $path substr($path3strlen($path)-3);
          return 
    $this->JoinUrlAndPath($url$path);
        } else if (
    substr($path02) == './') {
          
    $path substr($path2strlen($path)-2);
          return 
    $this->JoinUrlAndPath($url$path);
        } else {
          
    $domainPath substr($url0strrpos($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

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PHP6 View Post
    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:
    Code:
    /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
    Code:
    http://example.com/index.php/do/authorize/index.php/do/login/
    best regards

  • #3
    Regular Coder PHP6's Avatar
    Join Date
    Aug 2008
    Location
    Czech Republic
    Posts
    239
    Thanks
    18
    Thanked 34 Times in 33 Posts
    Quote Originally Posted by oesxyl View Post
    If action attribute is like that:
    Code:
    /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
    Code:
    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...

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PHP6 View Post
    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

  • #5
    Regular Coder PHP6's Avatar
    Join Date
    Aug 2008
    Location
    Czech Republic
    Posts
    239
    Thanks
    18
    Thanked 34 Times in 33 Posts
    Quote Originally Posted by oesxyl View Post
    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

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by PHP6 View Post
    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.

    Edit: rest is part of work,

    best regards

  • Users who have thanked oesxyl for this post:

    PHP6 (12-06-2008)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •