get the current URL and...

Discussion in 'PHP' started by buildakicker, Mar 13, 2006.

  1. #1
    Hello,

    I am trying to have a link to a page, retrieve the current URL and then change the .com and use the current /folder...

    Like:
    <a href ="<?php 
    GetCurrentURL = http://www.mydomain.com/go/ 
    change it to = http://www.mydomain2.com/go/ 
    
    ?> ">HERES MY LINK</>
    Code (markup):
    The folder does not change, but the .com does.

    Thanks!
     
    buildakicker, Mar 13, 2006 IP
  2. sketch

    sketch Well-Known Member

    Messages:
    898
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    148
    #2
    By "current URL" do you mean the webpage that the link is actively on? If so, maybe this is what you want (small chance I might be wrong :) ) :

    $forwardto = "somedomain.com";
    $currentURL = parseurl($_SERVER['URI_SCRIPT']);
    $outputURL = $forwardto.$currentURL['path'];
    PHP:
    This should turn "example.com/some/random/directory" to "somedomain.com/some/random/directory".
     
    sketch, Mar 13, 2006 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,828
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Or are you scraping content from someone else's site and changing the links to point to your own site, and then give dynamic search results?
     
    sarahk, Mar 13, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $theurl= parseurl($_SERVER['URI_SCRIPT']);
    $theurl= str_replace("mydomain", "mydomain2", $theurl);
    echo"$theurl";
    PHP:
     
    mad4, Mar 14, 2006 IP
  5. sketch

    sketch Well-Known Member

    Messages:
    898
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    148
    #5
    This code is a bit redundant in that it's going to search through every single element in the $theurl array for "mydomain"... AND it assumes the original URL will always be "mydomain" (it may be, but buildakicker hasn't responded yet). Mine ignores the original host name altogether (it doesn't matter) and appends the directory path to the final domain name.

    One fix to my code... should be parse_url, with the underscore.
     
    sketch, Mar 14, 2006 IP