Solved

Script ASP to PHP

Posted on 2011-09-14
4
294 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:swaggerking
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 36539574

<?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

0
 

Author Comment

by:swaggerking
ID: 36539711
Hey hielo.
Unfortunately it's not redirecting.
0
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 36539769
Copy and paste the code below:
<?php
$Thispage ="http://" . strtolower($_SERVER["SERVER_NAME"]) . $_SERVER["SCRIPT_NAME"];

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

Open in new window

0
 

Author Closing Comment

by:swaggerking
ID: 36539883
Much appreciation. It worked.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question