note 96001 deleted from function.parse-url by danbrown

From: Date: Tue, 02 Feb 2010 15:57:37 +0000
Subject: note 96001 deleted from function.parse-url by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165597@lists.php.net to get a copy of this message
Note Submitter: alessandro dot bondi at gmail dot com ---- 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.

« previous php.notes (#165597) next »