Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Newbie - .tk redirection script - please help

Status
Not open for further replies.

natesneat2000

Technical User
Jun 7, 2004
8
0
0
US
First, I am a newbie at PHP, else I would try to do this myself. I do have some Perl experioence though.
Basically, a .tk is a free domain that redirects you to your site. The address bar says your .tk location, though.
What I'd like to do is basically take the refferer (which should be the .tk) and strip off any subdomain or directory, and redirect you to the appropraite place.

Examples (please ignore trailing slash or lack thereof):
> (which is what it does now, but the address bar doesn't say so)
VoED.tpcc.tk > tpcc.servehttp.com/VoED
VoED.tpcc.tk/forum/ > tpcc.servehttp.com/VoED/forum/ (optional, but would be nice)
tpcc.tk/VoED > tpcc.servehttp.com/VoED

For bonus points, even let me set "shortcuts" in the script - example:
WFZ.tpcc.tk > tpcc.servehttp.com/Wades_File_Zone/

If anyone could do this, I would truly be most grateful, along with the people who visit my sites and forums!
 
Do up a function, include it in the header of every script. Have it do a preg_replace (that's a replacement function using perl's regex syntax). Then issue a header("Location:....") to the client.

Also, you probably want to make sure your 'real' httpd server is using some kind of 'CanonicalName' (I think that's it on Apache) option to give all links the fully qualified path (including the part). That way all links displayed will lead to where you really want them to end up.

----
JBR
 
First, I just plan to have one script, direct the .tk to it, and just have it do thte redirect.
preg_replace - a PHP function? Any examples? Again, I'm pretty new at PHP. My .tk would redirect anything to my no-ip sub, which... wont. That doesn't matter.
The only loop is we'd have to seperate the subdomain.

I have no clue how to do splits, but see if you can help me with them - I whipped this up. Also, the /'s may be iffy with the splits. Again, any help appreciated!

Code:
$pre_full = "[URL unfurl="true"]http://sub.tpcc.tk";[/URL] //address requested...$HTTP_REFFERER?
//I have no idea how the split function works :-D
//Split the first period off and keep everything before it
$ref_pre_pre = "split($pre_full,.)";
//split http:// off and check for www.

$ref_pre = "split($ref_pre_pre,//)
if ($ref_pre = "[URL unfurl="true"]www")[/URL]
   $ref_pre = "";

//Take everything after the .tk
$ref_post = "split($pre_full,.tk);
//What about the /? Without a post, there may not even be one either

//Build the URL
$redir = "[URL unfurl="true"]http://tpcc.servehttp.com"."$ref_pre"."ref_post";[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top