note 93781 deleted from function.strpos by levim

From: Date: Fri, 06 Dec 2013 16:31:41 +0000
Subject: note 93781 deleted from function.strpos by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197808@lists.php.net to get a copy of this message
Note Submitter: KimKha ---- 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); } ?>

« previous php.notes (#197808) next »