determining full url to page
Moderator: General Moderators
determining full url to page
let's say my site located at: http://www.webhost.com/~me/main.php
there is a line inside main.php: header("Location: full_url");
I want to specify dynamically complete url in this header...
$_SERVER['script_name'] gives only relative path...
how do i determine the http://..... part ?
thanks
there is a line inside main.php: header("Location: full_url");
I want to specify dynamically complete url in this header...
$_SERVER['script_name'] gives only relative path...
how do i determine the http://..... part ?
thanks
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
$_SERVER["SERVER_NAME"] gives you the server name part.
I don't know off hand how to determine the www part (should be automatic).
Why do you need the header("Location: full_url") when the relative path should send it correctly ?
As an aside the phpinfo() command is great to look up $_SERVER variables etc.
Have a phpinfo page consististing of
and take a look.
I don't know off hand how to determine the www part (should be automatic).
Why do you need the header("Location: full_url") when the relative path should send it correctly ?
As an aside the phpinfo() command is great to look up $_SERVER variables etc.
Have a phpinfo page consististing of
Code: Select all
<?php
phpinfo();
?>i read that specs reqiure full url... so there are maybe UA's that doesn't understand relative path...Why do you need the header("Location: full_url") when the relative path should send it correctly ?
i did printed $_SERVER variable so that why i'm asking because i don't see there anything that would hold complete url...
php manual also says that:
so i'm not sure whether it's good to use $_SERVER['SERVER_NAME']If the script is running on a virtual host, this will be the value defined for that virtual host.
in my case $_SERVER['SERVER_NAME'] contains ip and not dns name... is it always the case?
so i'm not sure if i can use this variable because of "virtual host" thing...
Code: Select all
function geturl()
{
$ports = array('https' => 443, 'http' => 80);
$prefix = empty($_SERVER['HTTPS']) ? 'http' : 'https';
$url = $prefix;
$url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : '';
$url .= '://';
$url .= $_SERVER['HTTP_HOST'];
$url .= $_SERVER['REQUEST_URI'];
return $url;
}- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada