Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Redirect script in php

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2009
Members
 
Join Date: Jan 2009
Posts: 41
Redirect script in php
  

hello i am hoping some help from here ,i am looking for code which will use to redirect url in php. i want this for following change "i have an old file that has SERP but i have structure and i want to leave that file in place but point it to the new file". please give me possible help as soon as thank you very much.

Reply With Quote
  #2  
Old 03-02-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Redirect script in php

for redirection you can use the header() function.You only have to take care that header() must be called before any actual output is deliver
Quote:
<?php

header('Location:http://www.php.net');

$f = fopen('demo.txt','w+');

fwrite($f,'Test');

fclose($f);

?>
Reply With Quote
  #3  
Old 03-02-2009
Member
 
Join Date: Dec 2008
Posts: 47
Re: Redirect script in php

This is PHP redirect() function, hope this will work for you ,use it .

Quote:
// func: redirect($to,$code=307)
// spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
function redirect($to,$code=301)
{
$location = null;
$sn = $_SERVER['SCRIPT_NAME'];
$cp = dirname($sn);
if (substr($to,0,4)=='http') $location = $to; // Absolute URL
else
{
$schema = $_SERVER['SERVER_PORT']=='443'?'https':'http';
$host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];
if (substr($to,0,1)=='/') $location = "$schema://$host$to";
elseif (substr($to,0,1)=='.') // Relative Path
{
$location = "$schema://$host/";
$pu = parse_url($to);
$cd = dirname($_SERVER['SCRIPT_FILENAME']).'/';
$np = realpath($cd.$pu['path']);
$np = str_replace($_SERVER['DOCUMENT_ROOT'],'',$np);
$location.= $np;
if ((isset($pu['query'])) && (strlen($pu['query'])>0)) $location.= '?'.$pu['query'];
}
}

$hs = headers_sent();
if ($hs==false)
{
if ($code==301) header("301 Moved Permanently HTTP/1.1"); // Convert to GET
elseif ($code==302) header("302 Found HTTP/1.1"); // Conform re-POST
elseif ($code==303) header("303 See Other HTTP/1.1"); // dont cache, always use GET
elseif ($code==304) header("304 Not Modified HTTP/1.1"); // use cache
elseif ($code==305) header("305 Use Proxy HTTP/1.1");
elseif ($code==306) header("306 Not Used HTTP/1.1");
elseif ($code==307) header("307 Temorary Redirect HTTP/1.1");
else trigger_error("Unhandled redirect() HTTP Code: $code",E_USER_ERROR);
header("Location: $location");
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
}
elseif (($hs==true) || ($code==302) || ($code==303))
{
// todo: draw some javascript to redirect
$cover_div_style = 'background-color: #ccc; height: 100%; left: 0px; position: absolute; top: 0px; width: 100%;';
echo "<div style='$cover_div_style'>\n";
$link_div_style = 'background-color: #fff; border: 2px solid #f00; left: 0px; margin: 5px; padding: 3px; ';
$link_div_style.= 'position: absolute; text-align: center; top: 0px; width: 95%; z-index: 99;';
echo "<div style='$link_div_style'>\n";
echo "<p>Please See: <a href='$to'>".htmlspecialchars($location)."</a></p>\n";
echo "</div>\n</div>\n";
}
exit(0);
}
Reply With Quote
  #4  
Old 03-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Redirect script in php

<? php
header ( "Location: http://site address.com");
>
<html>
<head>
<title> Redirect in PHP </ title>
</ head>
<body>
The code should be all 'top of page or return an error.
Replace http://site address.com with the site you want to be redirected to the visitor.
</ body>
</ html>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Redirect script in php"
Thread Thread Starter Forum Replies Last Post
Dumping logon name and logon script values to a text file - blank logon script field Phil McNeill Windows Server Help 3 17-08-2010 09:06 PM
Is it possible to execute Perl script within another script? RasMus Software Development 2 21-07-2009 10:57 PM
Word 2008 + bibfuse: no script in script menu deval4u Software Development 5 06-04-2009 12:53 PM
Problem with script in order to open another script in an extra window Samsher Software Development 2 14-01-2009 01:25 PM
Startup Script or Login Script ?? WANNABE Active Directory 5 22-12-2006 07:44 PM


All times are GMT +5.5. The time now is 01:36 AM.