Page 1 of 1

URL Parsing

Posted: Thu Mar 08, 2012 4:03 pm
by gazzieh
Is there a way of using PHP to capture the current URL (including parameters) and so using this to send as a session variable?

Re: URL Parsing

Posted: Thu Mar 08, 2012 4:13 pm
by social_experiment
I'm not sure what you are refering to (i innitially thought $_GET) but here is a url which could be useful
http://webcheatsheet.com/php/get_current_page_url.php

Re: URL Parsing

Posted: Thu Mar 08, 2012 7:08 pm
by Celauran
Threw this together in 2 minutes, so I can't promise it will work under every conceivable scenario.

Code: Select all

function getURL()
{
    $string  = (isset($_SERVER['HTTPS'])) ? 'https://' : 'http://';
    $string .= $_SERVER['SERVER_NAME'];
    $string .= $_SERVER['SCRIPT_NAME'];
    $string .= ($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '';
    return $string;
}