Self referencing

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

    Self referencing

    How can I write a PHP code to find the URL on which the code the itself
    is running?

    Sorry about the question: it's a bit difficult to describe, so here is
    what I am trying to achieve...

    ....in sort of LogicCode
    If this is NOT the home page then
    associate the company logo with a link to the home page
    else
    just display the logo without any linking reference.



    TIA
  • Andy Jeffries

    #2
    Re: Self referencing

    On Fri, 28 Apr 2006 21:03:54 +0800, TreatmentPlant wrote:[color=blue]
    > How can I write a PHP code to find the URL on which the code the itself is
    > running?[/color]

    If you're running PHP as an Apache module, use $_SERVER["REQUEST_UR I"].
    You can combine this with $_SERVER["HTTP_HOST"] if you run it on different
    hostnames (and that's important to you).

    Cheers,


    Andy

    --
    Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
    http://www.gphpedit.org | PHP editor for Gnome 2
    http://www.andyjeffries.co.uk | Personal site and photos

    Comment

    • Kevin Wells

      #3
      Re: Self referencing

      In message <44521287$0$307 19$5a62ac22@per-qv1-newsreader-01.iinet.net.au >
      TreatmentPlant <treatmentplant @DIESPAMMERS.ii net.net.au> wrote:
      [color=blue]
      >How can I write a PHP code to find the URL on which the code the itself
      >is running?
      >
      >Sorry about the question: it's a bit difficult to describe, so here is
      >what I am trying to achieve...
      >
      >...in sort of LogicCode
      >If this is NOT the home page then
      > associate the company logo with a link to the home page
      >else
      > just display the logo without any linking reference.
      >
      >
      >
      >TIA[/color]

      On the home page have something like this

      <? $page="home" ?> and on the other pages
      <? $page="nothome" ?>

      Then where you want the image to be have

      <?

      if ($page=="nothom e") {
      Code fopr company logo and link to home page code
      }
      else
      {
      Code for logo withouth link to home page
      }
      ?>





      --
      Kev Wells http://kevsoft.topcities.com

      ICQ 238580561
      Bring me my bow of burning gold!

      Comment

      • Shelly

        #4
        Re: Self referencing


        "Kevin Wells" <kev.wells@dsl. pipex.com> wrote in message
        news:d4f8aa1e4e .Kevin@pipex.co m...[color=blue]
        > In message <44521287$0$307 19$5a62ac22@per-qv1-newsreader-01.iinet.net.au >
        > TreatmentPlant <treatmentplant @DIESPAMMERS.ii net.net.au> wrote:
        >[color=green]
        >>How can I write a PHP code to find the URL on which the code the itself
        >>is running?
        >>
        >>Sorry about the question: it's a bit difficult to describe, so here is
        >>what I am trying to achieve...
        >>
        >>...in sort of LogicCode
        >>If this is NOT the home page then
        >> associate the company logo with a link to the home page
        >>else
        >> just display the logo without any linking reference.
        >>
        >>
        >>
        >>TIA[/color]
        >
        > On the home page have something like this
        >
        > <? $page="home" ?> and on the other pages
        > <? $page="nothome" ?>
        >
        > Then where you want the image to be have
        >
        > <?
        >
        > if ($page=="nothom e") {
        > Code fopr company logo and link to home page code
        > }
        > else
        > {
        > Code for logo withouth link to home page
        > }
        > ?>
        >[/color]

        Actually, all he need do is on the homepage
        <?php $page="somethin g" ?>
        and on all pages do
        if (isset($page)) {
        ....
        } else {
        ....
        }

        Shelly


        Comment

        • Andy Jeffries

          #5
          Re: Self referencing

          On Fri, 28 Apr 2006 15:18:25 -0400, Shelly wrote:[color=blue]
          > Actually, all he need do is on the homepage <?php $page="somethin g" ?>
          > and on all pages do
          > if (isset($page)) {
          > ...
          > } else {
          > ...
          > }
          > }[/color]

          But be wary of using it for anything more than changing a link like this,
          if you're running with register_global s on (I know, it's not good
          practice, but there may still be some old installations or those upgraded
          and kept for compatibility).

          At least Kevin's version would have checked for the exact value he set
          (rather than yours that would be got round with www.foo.com?page=1)

          Just pointing it out for less experienced PHPers.

          Cheers,


          Andy

          --
          Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
          http://www.gphpedit.org | PHP editor for Gnome 2
          http://www.andyjeffries.co.uk | Personal site and photos

          Comment

          • TreatmentPlant

            #6
            Re: Self referencing

            Kevin Wells wrote:[color=blue]
            > In message <44521287$0$307 19$5a62ac22@per-qv1-newsreader-01.iinet.net.au >
            > TreatmentPlant <treatmentplant @DIESPAMMERS.ii net.net.au> wrote:
            >[color=green]
            >> How can I write a PHP code to find the URL on which the code the itself
            >> is running?
            >>
            >> Sorry about the question: it's a bit difficult to describe, so here is
            >> what I am trying to achieve...
            >>
            >> ...in sort of LogicCode
            >> If this is NOT the home page then
            >> associate the company logo with a link to the home page
            >> else
            >> just display the logo without any linking reference.
            >>
            >>
            >>
            >> TIA[/color]
            >
            > On the home page have something like this
            >
            > <? $page="home" ?> and on the other pages
            > <? $page="nothome" ?>
            >
            > Then where you want the image to be have
            >
            > <?
            >
            > if ($page=="nothom e") {
            > Code fopr company logo and link to home page code
            > }
            > else
            > {
            > Code for logo withouth link to home page
            > }
            > ?>
            >
            >
            >
            >
            >[/color]
            Thanks all,

            I have implemented Kevin's suggestion and it works like a charm.

            Comment

            Working...