Variable for the Current URL and using it with another URL

Discussion in 'PHP' started by Correctus, Aug 30, 2006.

  1. #1
    Hi there,

    I needed a code that gets the current URL and stores it in a variable. Then I need a code which can fix that variable after another URL.

    For example if the current URL is digitalpoint.com/test.htm, the code will store it into a variable and then it will fix it after something like "seo.com/pagedetails.php?=" therefore resulting in "seo.com/pagedetails.php?=digitalpoint.com/test.htm" and then it should run that page as well.

    So can anyone make this script for me?

    IT
     
    Correctus, Aug 30, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The test.htm bit is stored as $PHP_SELF and I assume you know the sitename?

    $var="sitename.com/$PHP_SELF";

    $newpage="seo.com/pagedetails.php?=$var";
     
    mad4, Aug 31, 2006 IP
  3. Cryogenius

    Cryogenius Peon

    Messages:
    1,280
    Likes Received:
    118
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The variable $_SERVER['PHP_SELF'] would be better (use of $PHP_SELF is deprecated), or you could use $_SERVER['REQUEST_URI']. You can also use $_SERVER['HTTP_HOST'] to get the name of your site.

    $_SERVER['SCRIPT_URI'] can also work, and I think is the same.

    Cryo.
     
    Cryogenius, Aug 31, 2006 IP
  4. surefire

    surefire Guest

    Messages:
    40
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Whenever you want a quick reference of what variables are available to you on your specific host, you can use:

    print_r($_SERVER);

    Some variables found on Linux servers are not found on IIS servers. See www.php.net for more information on Global Variables. If you're just coding for your own server then it's not really an issue. Just run the code I posted above and what you see is what you can use. If you're coding for software/code to be sold or distributed, then you need to know the differences between global variables available on different types of hosts and the ways of getting around the limitations.
     
    surefire, Sep 1, 2006 IP
    Cryogenius likes this.