PHP equivalent?

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

    PHP equivalent?

    What's the PHP equivalent for the following?

    if(window.locat ion == "http:/site.com/page1.html")
    {

    }
    else
    {

    }

    Thanks,
    Don

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  • Daniel Tryba

    #2
    Re: PHP equivalent?

    Don <no@adr.com> wrote:[color=blue]
    > What's the PHP equivalent for the following?
    >
    > if(window.locat ion == "http:/site.com/page1.html")[/color]

    see:

    and construct the requested URI from the available elements.

    Comment

    • denisb

      #3
      Re: PHP equivalent?

      Don <no@adr.com> wrote:[color=blue]
      > What's the PHP equivalent for the following?
      > if(window.locat ion == "http:/site.com/page1.html") {
      >
      > } else {
      >
      > }[/color]

      $my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
      if ($my_page == "http:/site.com/page1.html") {

      } else {

      }

      if your page location is : http:/site.com/test/my_first/page1.php
      $_SERVER['HTTP_HOST'] return : site.com
      $_SERVER['PHP_SELF'] return : /test/my_first/page1.php

      --
      @@@@@
      E -00 comme on est very beaux dis !
      ' `) /
      |\_ =="

      Comment

      • Don

        #4
        Re: PHP equivalent?

        On 04 Mar 2005 23:16:42 GMT, Daniel Tryba <spam@tryba.inv alid> wrote:
        [color=blue]
        >Don <no@adr.com> wrote:[color=green]
        >> What's the PHP equivalent for the following?
        >>
        >> if(window.locat ion == "http:/site.com/page1.html")[/color]
        >
        >see:
        >http://www.php.net/manual/en/reserve...riables.server
        >and construct the requested URI from the available elements.[/color]
        Thanks Daniel.

        ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
        http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
        ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

        Comment

        • Don

          #5
          Re: PHP equivalent?

          On Sat, 5 Mar 2005 00:18:38 +0100, newdb@no-log.org (denisb) wrote:
          [color=blue]
          >Don <no@adr.com> wrote:[color=green]
          >> What's the PHP equivalent for the following?
          >> if(window.locat ion == "http:/site.com/page1.html") {
          >>
          >> } else {
          >>
          >> }[/color]
          >
          >$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
          >if ($my_page == "http:/site.com/page1.html") {
          >
          >} else {
          >
          >}
          >
          >if your page location is : http:/site.com/test/my_first/page1.php
          >$_SERVER['HTTP_HOST'] return : site.com
          >$_SERVER['PHP_SELF'] return : /test/my_first/page1.php[/color]
          Thanks much. That works just great.
          Don

          ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
          http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
          ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

          Comment

          • Michael Fesser

            #6
            Re: PHP equivalent?

            .oO(denisb)
            [color=blue]
            >Don <no@adr.com> wrote:
            >[color=green]
            >> What's the PHP equivalent for the following?
            >> if(window.locat ion == "http:/site.com/page1.html") {
            >>
            >> } else {
            >>
            >> }[/color]
            >
            >$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];[/color]

            $_SERVER['PHP_SELF'] contains the name of the currently running script,
            but that doesn't necessarily have to be the requested URI as seen in the
            browser's address bar. $_SERVER['REQUEST_URI'] will be more accurate.

            Micha

            Comment

            • Joshua Beall

              #7
              Re: PHP equivalent?

              if("{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}" ===
              'mysite.com/pageWhatever.ph p')
              {
              echo "We're here with pageWhatever.ph p at mysite.com, reporting live!
              Now it's time for a commercial break";
              }
              else
              {
              echo "Standby for signal...";
              }

              Untested, I'm not actually sure if you need a slash between the two
              variables. Try it yourself and see what you get.

              -jb

              "Don" <no@adr.com> wrote in message
              news:s2ph219eu4 69euk5rhvv76l39 igvlu8mdl@4ax.c om...[color=blue]
              > What's the PHP equivalent for the following?
              >
              > if(window.locat ion == "http:/site.com/page1.html")
              > {
              >
              > }
              > else
              > {
              >
              > }
              >
              > Thanks,
              > Don
              >
              > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
              > News==----
              > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
              > Newsgroups
              > ----= East and West-Coast Server Farms - Total Privacy via Encryption
              > =----[/color]


              Comment

              • denisb

                #8
                Re: PHP equivalent?

                Michael Fesser <netizen@gmx.ne t> wrote:[color=blue]
                > .oO(denisb)[color=green]
                > >Don <no@adr.com> wrote:[color=darkred]
                > >> What's the PHP equivalent for the following?
                > >> if(window.locat ion == "http:/site.com/page1.html") {
                > >> } else {
                > >> }[/color]
                > >$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];[/color]
                > $_SERVER['PHP_SELF'] contains the name of the currently running script,
                > but that doesn't necessarily have to be the requested URI as seen in the
                > browser's address bar. $_SERVER['REQUEST_URI'] will be more accurate.[/color]

                yes, it's true.
                you are right.

                --
                @@@@@
                E -00 comme on est very beaux dis !
                ' `) /
                |\_ =="

                Comment

                • John Dunlop

                  #9
                  PHP_SELF and REQUEST_URI

                  Michael Fesser wrote:
                  [color=blue]
                  > $_SERVER['PHP_SELF'] contains the name of the currently running script,[/color]

                  Please, no! Words like 'name' and 'script' only keep the
                  confusion alive. PHP_SELF is simply the path part of the
                  current resource's URI. There can be all sorts of rewriting
                  going on backstage which lead to an address bearing no
                  resemblance to the name of the script it identifies.
                  [color=blue]
                  > but that doesn't necessarily have to be the requested URI as seen in the
                  > browser's address bar.[/color]

                  True, since an address bar normally shows a URI, the one the
                  browser parsed to make the request.
                  [color=blue]
                  > $_SERVER['REQUEST_URI'] will be more accurate.[/color]

                  Accuracy doesn't come in to it. You can build the current
                  URI with REQUEST_URI or PHP_SELF, but they are not the same.

                  Typically, Request-URI is an absolute-path reference,* that
                  is, it begins with a single slash. Then, if there is no
                  query part, REQUEST_URI and PHP_SELF are identical; they are
                  both the path part of the current resource's URI. If there
                  is a query part, however, then

                  PHP_SELF + '?' + QUERY_STRING = REQUEST_URI

                  The Manual happens to be wrong. It says, without a
                  semblance of uncertainty, that PHP_SELF is 'the filename of
                  the currently executing script', which is inexcusable coming
                  from an authority of its stature.



                  Have a good weekend, Micha!


                  * But it can also be, among other things, a URI, which
                  REQUEST_URI should mirror. For example, a Request-line:

                  GET http://host.invalid/path?query HTTP/1.1

                  should give a REQUEST_URI of
                  <http://host.invalid/path?query>.

                  --
                  Jock

                  Comment

                  • Don

                    #10
                    Re: PHP equivalent?

                    On Fri, 04 Mar 2005 15:45:23 -0700, Don <no@adr.com> wrote:
                    [color=blue]
                    >What's the PHP equivalent for the following?
                    >
                    > if(window.locat ion == "http:/site.com/page1.html")
                    > {
                    >
                    > }
                    > else
                    > {
                    >
                    > }
                    >
                    >Thanks,
                    >Don
                    >
                    >----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
                    >http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
                    >----= East and West-Coast Server Farms - Total Privacy via Encryption =----[/color]
                    Thanks much for all of your help.
                    Don

                    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
                    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
                    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

                    Comment

                    • Michael Fesser

                      #11
                      Re: PHP_SELF and REQUEST_URI

                      .oO(John Dunlop)
                      [color=blue]
                      >Michael Fesser wrote:
                      >[color=green]
                      >> $_SERVER['PHP_SELF'] contains the name of the currently running script,[/color]
                      >
                      >Please, no! Words like 'name' and 'script' only keep the
                      >confusion alive. PHP_SELF is simply the path part of the
                      >current resource's URI.[/color]

                      Not necessarily.
                      [color=blue]
                      >True, since an address bar normally shows a URI, the one the
                      >browser parsed to make the request.[/color]

                      And the one the OP asked for.
                      [color=blue]
                      >Typically, Request-URI is an absolute-path reference,* that
                      >is, it begins with a single slash. Then, if there is no
                      >query part, REQUEST_URI and PHP_SELF are identical;[/color]

                      If the browser requested '/', PHP_SELF with contain '/index.php'. I
                      don't consider that identical.

                      And it gets even more complicated with server-side URI rewriting. In my
                      current testing scripts PHP_SELF will always contain the same value,
                      regardless of the requested URI.
                      [color=blue]
                      >Typically, Request-URI is an absolute-path reference,* that
                      >is, it begins with a single slash.[/color]

                      Yep.
                      [color=blue]
                      >Then, if there is no
                      >query part, REQUEST_URI and PHP_SELF are identical; they are
                      >both the path part of the current resource's URI.[/color]

                      Again: Not necessarily.
                      [color=blue]
                      >The Manual happens to be wrong. It says, without a
                      >semblance of uncertainty, that PHP_SELF is 'the filename of
                      >the currently executing script', which is inexcusable coming
                      >from an authority of its stature.[/color]

                      But that's exactly what PHP_SELF is.

                      Micha

                      Comment

                      • John Dunlop

                        #12
                        Re: PHP_SELF and REQUEST_URI

                        Michael Fesser wrote:
                        [color=blue]
                        > .oO(John Dunlop)[/color]
                        [color=blue][color=green]
                        > >Please, no! Words like 'name' and 'script' only keep the
                        > >confusion alive. PHP_SELF is simply the path part of the
                        > >current resource's URI.[/color]
                        >
                        > Not necessarily.[/color]

                        Aha! I was wrong. Thank you for putting me right. May I
                        repay you now?
                        [color=blue][color=green]
                        > >Typically, Request-URI is an absolute-path reference,* that
                        > >is, it begins with a single slash. Then, if there is no
                        > >query part, REQUEST_URI and PHP_SELF are identical;[/color]
                        >
                        > If the browser requested '/', PHP_SELF with contain '/index.php'.[/color]

                        Mine shows '/index', without '.php', even though '.php' is
                        part of the filename. The filename is 'index.php', not
                        '/index' or 'index'. So in this case PHP_SELF isn't the
                        filename. In fact, filenames here cannot contain slashes,
                        and backslashes, not slashes, show directory structure, so
                        PHP_SELF can't be a filesystem path either.
                        [color=blue]
                        > I don't consider that identical.[/color]

                        Nor do I. You're right.
                        [color=blue]
                        > And it gets even more complicated with server-side URI rewriting. In my
                        > current testing scripts PHP_SELF will always contain the same value,
                        > regardless of the requested URI.[/color]

                        Fascinating. Here, if I request <http://127.0.0.1/php/foo>,
                        PHP_SELF is '/php/foo' -- not the filename of the script.
                        If I request <http://127.0.0.1/php/foo.php>, PHP_SELF is
                        '/php/foo.php' -- again, not the filename. Both URIs
                        identify the same resource, by the way.
                        [color=blue][color=green]
                        > >The Manual happens to be wrong. It says, without a
                        > >semblance of uncertainty, that PHP_SELF is 'the filename of
                        > >the currently executing script', which is inexcusable coming
                        > >from an authority of its stature.[/color]
                        >
                        > But that's exactly what PHP_SELF is.[/color]

                        I've shown that to be untrue, haven't I?

                        --
                        Jock

                        Comment

                        • Michael Fesser

                          #13
                          Re: PHP_SELF and REQUEST_URI

                          .oO(John Dunlop)
                          [color=blue]
                          >Fascinating. Here, if I request <http://127.0.0.1/php/foo>,
                          >PHP_SELF is '/php/foo' -- not the filename of the script.
                          >If I request <http://127.0.0.1/php/foo.php>, PHP_SELF is
                          >'/php/foo.php' [...][/color]

                          This happens with content negotiation (MultiViews) enabled on the
                          server.
                          [color=blue][color=green][color=darkred]
                          >> >The Manual happens to be wrong. It says, without a
                          >> >semblance of uncertainty, that PHP_SELF is 'the filename of
                          >> >the currently executing script', which is inexcusable coming
                          >> >from an authority of its stature.[/color]
                          >>
                          >> But that's exactly what PHP_SELF is.[/color]
                          >
                          >I've shown that to be untrue, haven't I?[/color]

                          OK, it's "the path and filename of the currently executing script".
                          At least in most cases ... ;)

                          Micha

                          Comment

                          Working...