$_SERVER in a class
Posted: Thu Dec 28, 2006 2:27 pm
How would I use $_SERVER in a class? I am getting an error in my IDE
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
var $request = $_SERVER['REQUEST_URI']; //Gets Full URL
var $dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
var $url = explode("/", $dirs); //Puts URL Dirs into array $urlthomas777neo wrote:You should be able to use it anywhere as it is a global variable.
Perhaps post some code that you can be assisted further
Code: Select all
class guav_engine
{
var $url;
var $method;
//Get the URL
var $request = $_SERVER['REQUEST_URI']; //Gets Full URL
var $dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
var $url = explode("/", $dirs); //Puts URL Dirs into array $url
function guav_sys_method_get() //Split $method from $url
{
global $method, $url;
m_catch(admin, admin);
m_catch(home, sys);
m_catch(blog, sys);
m_catch(null, sys);
m_catch(page, page);
return $method;
}
$max = count($url); //Split the $dir from $url
for ($i=1;$i==$max;$i++)
{
$dir[$i-1] = $url[$i];
}How do I put it in a different method or constructor?Jcart wrote:I've already answered your question.
Code: Select all
class guav_engine
{
var $url;
var $method;
var $request;
var $dirs;
var $url;
function __construct()
{
//Get the URL
$this->request = $_SERVER['REQUEST_URI']; //Gets Full URL
$this->dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
$this->url = explode("/", $dirs); //Puts URL Dirs into array $url
}
function guav_sys_method_get() //Split $method from $url
{
global $method, $url;
m_catch(admin, admin);
m_catch(home, sys);
m_catch(blog, sys);
m_catch(null, sys);
m_catch(page, page);
return $method;
}
$max = count($url); //Split the $dir from $url
for ($i=1;$i==$max;$i++)
{
$dir[$i-1] = $url[$i];
}
//....Code: Select all
class foobar
{
var $request;
var $dirs;
function foobar()
{
$this->request = $_SERVER['REQUEST_URI'];
$this->dirs = parse_url($this->request, PHP_URL_PATH);
//...
}
}