Free Advertising - Loans - Loans - Credit Counseling - Loans

PDA

View Full Version : get the current URL and...


buildakicker
Mar 13th 2006, 3:59 pm
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</>

The folder does not change, but the .com does.

Thanks!

sketch
Mar 13th 2006, 4:39 pm
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'];

This should turn "example.com/some/random/directory" to "somedomain.com/some/random/directory".

sarahk
Mar 13th 2006, 4:51 pm
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?

mad4
Mar 14th 2006, 5:07 am
$theurl= parseurl($_SERVER['URI_SCRIPT']);
$theurl= str_replace("mydomain", "mydomain2", $theurl);
echo"$theurl";

sketch
Mar 14th 2006, 10:25 am
$theurl= parseurl($_SERVER['URI_SCRIPT']);
$theurl= str_replace("mydomain", "mydomain2", $theurl);
echo"$theurl";

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.