URL Parsing

gazzieh

New Member
Is there a way of using PHP to capture the current URL (including parameters) and so using this to send as a session variable?
 

conor

New Member
Here's a function I wrote a while ago to do just that. It works for port numbers and for https if they are present:

Code:
/**
 * calculate_url
 *
 * Accurately calculates the URL
 * 
 * @access public
 * @return string
 */
function calculate_url( ){
        $url = 'http';

        if( $_SERVER[ 'HTTPS' ] == 'on' )
                $url .= 's';

        $url .= '://' . $_SERVER[ 'SERVER_NAME' ];

        if( $_SERVER[ 'SERVER_PORT' ] != '80' )
                $url .= ':' . $_SERVER[ 'SERVER_PORT' ];

        $url .= $_SERVER[ 'REQUEST_URI' ];
        $url .= $_SERVER[ 'QUERY_STRING' ];

        return $url;
}
 
Top