Solved

Script ASP to PHP

Posted on 2011-09-14
4
285 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now