URL Parsing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

URL Parsing

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: URL Parsing

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: URL Parsing

Post 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;
}
Post Reply