?
Solved

Script ASP to PHP

Posted on 2011-09-14
4
Medium Priority
?
305 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
[X]
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
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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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