note 96001 added to function.parse-url

From: Date: Tue, 02 Feb 2010 09:43:53 +0000
Subject: note 96001 added to function.parse-url
Groups: php.notes 
Request: Send a blank email to php-notes+get-165591@lists.php.net to get a copy of this message
This is a modified version of get_url that considers the port number too. function get_url() { $arr = array(); $uri = $_SERVER['REQUEST_URI']; // query $x = array_pad( explode( '?', $uri ), 2, false ); $arr['query'] = ( $x[1] )? $x[1] : '' ; // resource $x = array_pad( explode( '/', $x[0] ), 2, false ); $x_last = array_pop( $x ); if( strpos( $x_last, '.' ) === false ) { $arr['resource'] = ''; $x[] = $x_last; } else { $arr['resource'] = $x_last; } // path $arr['path'] = implode( '/', $x ); if( substr( $arr['path'], -1 ) !== '/' ) $arr['path'] .= '/'; // domain $arr['host'] = $_SERVER['SERVER_NAME']; // scheme $server_prt = explode( '/', $_SERVER['SERVER_PROTOCOL'] ); $arr['scheme'] = strtolower( $server_prt[0] ); // port $arr['port'] = $_SERVER['SERVER_PORT']; // url $arr['url'] = $arr['scheme'].'://'.$arr['host']; if (strlen($arr['port'])>0) $arr['url'].=":".$arr['port']; $arr['url'].=$uri; return $arr; } username, password and fragment cannot be read from server variables. ---- Server IP: 69.147.83.197 Probable Submitter: 79.29.100.163 ---- Manual Page -- http://www.php.net/manual/en/function.parse-url.php Edit -- https://master.php.net/note/edit/96001 Del: integrated -- https://master.php.net/note/delete/96001/integrated Del: useless -- https://master.php.net/note/delete/96001/useless Del: bad code -- https://master.php.net/note/delete/96001/bad+code Del: spam -- https://master.php.net/note/delete/96001/spam Del: non-english -- https://master.php.net/note/delete/96001/non-english Del: in docs -- https://master.php.net/note/delete/96001/in+docs Del: other reasons-- https://master.php.net/note/delete/96001 Reject -- https://master.php.net/note/reject/96001 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165591) next »