Jump to content

[SOLVED] Geting the current url


SyncViews

Recommended Posts

How can I get the url for the current page in php?

 

I tried these but none returned the exact url :(

 

 

$_SERVER['SCRIPT_NAME']

$_SERVER['PHP_SELF']

__FILE__

 

I just want it to to just get the same url as dsiplayed in the user adress bar.. (includeing the domain and ?myvar = value etc). I'd also rather this can work from within an included file and still returnt he correct url)

 

Link to comment
Share on other sites

You can use $_SERVER['REQUEST_URI'] for that.

 

Edit: That won't get the entire URL though. You'll need to combine some different variables like this:

<?php
switch($_SERVER['SERVER_PORT'])
{
default:
case 80:
	$url = 'http';
	break;
case 443:
	$url = 'https';
	break;
}
$url .= '://'.$_SERVER['SERVER_NAME'].(!in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? ':'.$_SERVER['SERVER_PORT'] : null).$_SERVER['REQUEST_URI'];

echo $url;
?>

Link to comment
Share on other sites

that didn't return the entire url though. just the bit that comes after the domain :(

(eg"/forums/index.php/topic,172438.0.html")

 

I want a way to get the domain as well so when I move the site onto the internet I don't have to go through and change stuff like that...

 

(so I want "http://www.phpfreaks.com/forums/index.php/topic,172438.0.html" rather than the above)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.