note 93781 modified in function.strpos by danbrown
| From: | danbrown@php.net | Date: | Tue, 29 Sep 2009 15:35:09 +0000 |
| Subject: | note 93781 modified in function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161148@lists.php.net to get a copy of this message | ||
The following function use to redirect to URL correctly if the URL have "http://" or "https://", or to
relative URL on your site.
<?php
function forward($url = NULL){
$root = "http://example.com/mydir/";
if($url == NULL) // Go to homepage
$url = $root;
else {
$pos = strpos($url, "http://");
if ($pos === false)
$pos = strpos($url, "https://");
if ($pos === false || $pos > 0) // Go to relative URL on your site
$url = $root . $url;
}
header('Location:'.$url);
}
?>
--was--
The following function use to redirect to URL correctly if the URL have "http://" or "https://", or to
relative URL on your site.
<?php
function forward($url = NULL){
$root = "http://localhost/mydir/";
if($url == NULL) // Go to homepage
$url = $root;
else {
$pos = strpos($url, "http://");
if ($pos === false)
$pos = strpos($url, "https://");
if ($pos === false || $pos > 0) // Go to relative URL on your site
$url = $root . $url;
}
header('Location:'.$url);
}
?>
http://php.net/manual/en/function.strpos.php