Script ASP to PHP

Posted on 2011-09-14
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.
redirect to
Thispage ="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")

If Instr(ThisPage, "") Then
Thispage = Replace(Thispage, "", "") 
response.redirect (ThisPage)
End If

Open in new window

Question by:swaggerking
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 82

Expert Comment

ID: 36539574

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

if( false!==strpos($ThisPage, "") )
	$Thispage = str_replace($Thispage, "", "");
	header ('Location: '. $ThisPage);

Open in new window


Author Comment

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

Accepted Solution

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

if( false!==strpos($Thispage, "") )
	$Thispage = str_replace("", "", $Thispage );
	header ('Location: '. $Thispage);

Open in new window


Author Closing Comment

ID: 36539883
Much appreciation. It worked.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
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…
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.

724 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