URL parsing in order to use as a variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dylan

    URL parsing in order to use as a variable

    Can anyone tell me if it's possible to enter a URL such as

    www.streetfish.co.uk is available for sale. Check out price, information and more on Dovendi.com


    and take the number and pass it to the index.php script (where the
    number is the user's mySQL user id.

    This is pretty much what happens with tinyurl.com (as far as I
    understand) but the examples I have read regarding this are using
    different technologies.

    If anyone can help, or if you can let me know if you've seen a similar
    example, I'd appreciate some help.

    Thanks,

    Dylan

  • Peter Fox

    #2
    Re: URL parsing in order to use as a variable

    Following on from dylan's message. . .[color=blue]
    >Can anyone tell me if it's possible to enter a URL such as
    >
    >http://www.streetfish.co.uk/1234
    >
    >and take the number and pass it to the index.php script (where the
    >number is the user's mySQL user id.[/color]

    The functionality you want is in the web server itself.
    Look in the Apache docs for something like (never done it) URL
    Rewriting.
    --
    PETER FOX Not the same since the submarine business went under
    peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
    2 Tees Close, Witham, Essex.
    Gravity beer in Essex <http://www.eminent.dem on.co.uk>

    Comment

    • Michael

      #3
      Re: URL parsing in order to use as a variable

      Ok, I don't know exactly, but you would use an .htaccess script I
      expect to get the address sent to a php script, then from that use the
      substr command to take out the main url leaving you with 1234 which you
      could put into a variable. You could just have something like this
      though : streetfish.co.u k/link?id=1234 much easier.

      Comment

      • Michael

        #4
        Re: URL parsing in order to use as a variable

        @Peter: His server is ISS so he wont find anything helpful looking at
        the apache docs, look at the errorpages.

        Comment

        • Csaba Gabor

          #5
          Re: URL parsing in order to use as a variable

          dylan wrote:[color=blue]
          > Can anyone tell me if it's possible to enter a URL such as
          >
          > http://www.streetfish.co.uk/1234[/color]

          On Apache, there is an AcceptPathInfo= on directive, which should do
          what you want (the corresponding variable in PHP is PATH_INFO - see
          http://php.net/reserved.variables). Only it doesn't. I logged this as
          a bug at: http://issues.apache.org/bugzilla/show_bug.cgi?id=8880 but it
          was denied (they suggest a workaround at the bottom of the report). I
          never did understand why they didn't want to do fix it.

          I also didn't implement their suggestion because I now (as I suspect
          most others) use url rewriting, a little of which is described at:
          http://www.codecomments.com/archive2...-8-574178.html (of course,
          there is more documentation at
          http://httpd.apache.org/docs/2.0/urlmapping.html and
          http://httpd.apache.org/docs/2.0/misc/rewriteguide.html)

          By the way, notice that PHP address above. It's doing the same thing
          you want done. Don't know what to tell you for non Apache.

          Csaba Gabor from Vienna

          Comment

          • Csaba Gabor

            #6
            Re: URL parsing in order to use as a variable

            dylan wrote:[color=blue]
            > Can anyone tell me if it's possible to enter a URL such as
            >
            > http://www.streetfish.co.uk/1234
            > and take the number and pass it to the index.php script (where the[/color]

            On Apache, there is an AcceptPathInfo= on directive, which should do
            what you want (the corresponding variable in PHP is PATH_INFO - see
            http://php.net/reserved.variables - notice they are also doing what you
            want). Only it doesn't. I logged this as a bug at:
            http://issues.apache.org/bugzilla/show_bug.cgi?id=8880 but it was
            denied (they suggest a workaround at the bottom of the report). I
            never did understand why they didn't want to do fix it.

            I also didn't implement their suggestion because I now (as I suspect
            most others) use url rewriting, a little of which is described at:
            http://www.codecomments.com/archive2...-8-574178.html (of course,
            there is more documentation at
            http://httpd.apache.org/docs/2.0/urlmapping.html and
            http://httpd.apache.org/docs/2.0/mis...iteguide.html). There is
            also a concrete example at:


            Don't know what to tell you for non Apache.

            Csaba Gabor from Vienna

            Comment

            • raju_sykam@yahoo.com

              #7
              Re: URL parsing in order to use as a variable

              <?
              $url= $_SERVER['PHP_SELF']; //gives you url
              $userid=strrchr ($url,"/"); // gives u /1234
              $userid=substr( $file,1); // gives u 1234 by eliminating /

              /* i think u got it */
              ?>

              <?php

              echo $_SERVER['HTTP_HOST']; //outputs sitename.com etc
              echo $_SERVER['REQUEST_URI']; //outputs /index.php etc
              ?>

              Comment

              • dylan

                #8
                Re: URL parsing in order to use as a variable

                hi,

                Thanks for your help on this, been really busy lately, and only now
                getting a chance to look at this,

                I'll let you know how I get on.

                Dylan

                Comment

                Working...