Link to home
Start Free TrialLog in
Avatar of swaggerking
swaggerkingFlag for United States of America

asked on

Script ASP to PHP

I need help converting the attached code from ASP to PHP for an internal site. I don't know PHP and the online ASP to PHP converters I found don't seem to be doing the job. 301 Redirects are not an option.

Basically I'm trying to find servers domain name, then check the string to see if I contains the older domain name, if so I want to replace the older domain name and redirect.
Example:
http://www.oldsite.com/somepage
redirect to
http://www.newsite.com/somepage
<%
Thispage ="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")

If Instr(ThisPage, "oldsite.com") Then
Thispage = Replace(Thispage, "oldsite.com", "newsite.com") 
response.redirect (ThisPage)
End If
%>

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image


<?php
$Thispage ="http://" . strtolower($_SERVER["SERVER_NAME"]) . $_SERVER["SCRIPT_NAME"];

if( false!==strpos($ThisPage, "oldsite.com") )
{
	$Thispage = str_replace($Thispage, "oldsite.com", "newsite.com");
	header ('Location: '. $ThisPage);
	exit;
}
?>

Open in new window

Avatar of swaggerking

ASKER

Hey hielo.
Unfortunately it's not redirecting.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Much appreciation. It worked.