note 93781 added to function.strpos

From: Date: Tue, 29 Sep 2009 08:56:07 +0000
Subject: note 93781 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-161133@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://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); } ?> ---- Server IP: 112.213.92.44 Probable Submitter: 118.68.100.167 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/93781 Del: integrated -- https://master.php.net/note/delete/93781/integrated Del: useless -- https://master.php.net/note/delete/93781/useless Del: bad code -- https://master.php.net/note/delete/93781/bad+code Del: spam -- https://master.php.net/note/delete/93781/spam Del: non-english -- https://master.php.net/note/delete/93781/non-english Del: in docs -- https://master.php.net/note/delete/93781/in+docs Del: other reasons-- https://master.php.net/note/delete/93781 Reject -- https://master.php.net/note/reject/93781 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161133) next »