absolute links with $_SERVER['SERVER_NAME'] issue
Moderator: General Moderators
absolute links with $_SERVER['SERVER_NAME'] issue
Hi all.
Having some issues with $_SERVER['SERVER_NAME'] making absolute links. $_SERVER['SERVER_NAME'] it self echo to "intranet" and when i do http://".$_SERVER['SERVER_NAME']."/index.php it make the link to http://intranet/intranet/index.php..... does anyone know why???
Rippie
Having some issues with $_SERVER['SERVER_NAME'] making absolute links. $_SERVER['SERVER_NAME'] it self echo to "intranet" and when i do http://".$_SERVER['SERVER_NAME']."/index.php it make the link to http://intranet/intranet/index.php..... does anyone know why???
Rippie
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: absolute links with $_SERVER['SERVER_NAME'] issue
Have you tried using $_SERVER['SERVER_ADDR'] or $_SERVER['HTTP_HOST'] instead to see what happens?
This article explains where the $_SERVER['SERVER_NAME'] is derived from, which might explain the results you're getting:
http://shiflett.org/blog/2006/mar/serve ... -http-host
HTH,
Mecha Godzilla
This article explains where the $_SERVER['SERVER_NAME'] is derived from, which might explain the results you're getting:
http://shiflett.org/blog/2006/mar/serve ... -http-host
HTH,
Mecha Godzilla
Re: absolute links with $_SERVER['SERVER_NAME'] issue
HTTP_HOST worked like a treat.. Thank you very much for your reply.
Re: absolute links with $_SERVER['SERVER_NAME'] issue
mecha_godzilla,
Thinking of including a systemvariables.php on each of my pages where i could have $siteaddress = "http://mydomain.com"; and another one for the include paths so when i need to link to something i can do echo "$siteaddress/path/file.xxx"; that way i only need to change 1 place if my domain name changes. what is your thoughts on this ?
Rippie
Thinking of including a systemvariables.php on each of my pages where i could have $siteaddress = "http://mydomain.com"; and another one for the include paths so when i need to link to something i can do echo "$siteaddress/path/file.xxx"; that way i only need to change 1 place if my domain name changes. what is your thoughts on this ?
Rippie
Re: absolute links with $_SERVER['SERVER_NAME'] issue
Merca
Just found an application that uses a big like what i want to use.... look at this
but must say i am not sure if it is any smart to do global $CONF and not sure why unset $CONF. can you cast some light on this ?
Just found an application that uses a big like what i want to use.... look at this
Code: Select all
global $CONF;
unset($CONF);
/**
* PERSONALIZATION
* You can alter these entries to personalize your TeamCal Pro installation.
* You might also want to look at the indludes/header.application.inc.php
* file if you want to display your own header image.
* Sample:
* $CONF['app_root'] = $_SERVER['DOCUMENT_ROOT']."/tcpro/";
* $CONF['app_url'] = "http://www.myserver.com/tcpro";
*/
$CONF['app_root'] = $_SERVER['DOCUMENT_ROOT']."/teamcal/";
$CONF['app_url'] = "http://www.rippie.dk/teamcal";
$CONF['app_avatar_dir'] = 'img/avatar/';
$CONF['app_icon_dir'] = 'img/icons/';- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: absolute links with $_SERVER['SERVER_NAME'] issue
Hmm...I think I need to see the full script to answer that one 
The point of having the unset() in there is to destroy any local instances of $CONF but I'm not sure why that would be useful in this particular script. From the looks of it, this code must be from part of a function because global is being used to access $CONF and $CONF must therefore have already been defined in the main body of the script somewhere. I'll be honest, I've always found the way PHP does local and global variables a bit strange (at least, it doesn't seem like the "normal" way to do it) but I would guess that maybe this bit of code is included as a way to make sure that the values aren't accidentally added to a 'local' $CONF array instead of the 'global' $CONF array.
Does that make any sense? If you want a proper answer, post the full code!
M_G
The point of having the unset() in there is to destroy any local instances of $CONF but I'm not sure why that would be useful in this particular script. From the looks of it, this code must be from part of a function because global is being used to access $CONF and $CONF must therefore have already been defined in the main body of the script somewhere. I'll be honest, I've always found the way PHP does local and global variables a bit strange (at least, it doesn't seem like the "normal" way to do it) but I would guess that maybe this bit of code is included as a way to make sure that the values aren't accidentally added to a 'local' $CONF array instead of the 'global' $CONF array.
Does that make any sense? If you want a proper answer, post the full code!
M_G
Re: absolute links with $_SERVER['SERVER_NAME'] issue
Code: Select all
<?php
/**
* config.default.php
*
* Contains the default config parameters. Is being read by the installation
* script and used to create config.tcpro.php.
*
* @package TeamCalPro
* @version 3.2
* @author George Lewe
* @copyright Copyright (c) 2004-2009 by George Lewe
* @link http://www.lewe.com
* @license http://www.lewe.com/tcpro/doc/license.txt Extended GNU Public License
*/
global $CONF;
unset($CONF);
/**
* PERSONALIZATION
* You can alter these entries to personalize your TeamCal Pro installation.
* You might also want to look at the indludes/header.application.inc.php
* file if you want to display your own header image.
* Sample:
* $CONF['app_root'] = $_SERVER['DOCUMENT_ROOT']."/tcpro/";
* $CONF['app_url'] = "http://www.myserver.com/tcpro";
*/
$CONF['app_root'] = $_SERVER['DOCUMENT_ROOT']."/tcpro/";
$CONF['app_url'] = "http://localhost/tcpro";
$CONF['app_avatar_dir'] = 'img/avatar/';
$CONF['app_icon_dir'] = 'img/icons/';
/**
* DATABASE
* Currently only db_type=1 (MySQL) is supported.
*/
$CONF['db_type'] = 1;
$CONF['db_persistent'] = false;
$CONF['db_server'] ="localhost";
$CONF['db_name'] ="test";
$CONF['db_user'] ="root";
$CONF['db_pass'] ="";
?>- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: absolute links with $_SERVER['SERVER_NAME'] issue
I don't think $CONF is any kind of special/reserved value, but you might want to check if the TeamCal scripts use any other libraries that rely on it. If you're writing a completely new script from scratch then you can use whatever names you want - some of these values (such as the root folder of the application) could be defined as a constant instead of as a key/value pair in an array, by using:
or
The good thing about using constants is that they're available to all parts of the script so you don't have to keep declaring global $app_root or whatever in all your functions. You do need to be careful about not having any spaces in the name though, or if you do then you need to reference them as constant("APPLICATION ROOT") instead.
Does that answer your question?
M_G
Code: Select all
DEFINE("APPLICATION_ROOT", "/path/to/my/webfolder/");
echo 'The application root folder is: ' . APPLICATION_ROOT;Code: Select all
DEFINE("APPLICATION_ROOT", $_SERVER['HTTP_HOST']);
echo 'The application root folder is: ' . APPLICATION_ROOT;Does that answer your question?
M_G