$_SERVER in a class
Moderator: General Moderators
$_SERVER in a class
How would I use $_SERVER in a class? I am getting an error in my IDE
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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 $url'parse error } at end of class statement...' a bunch of those, although I have combed through my code and I can't find a single decimal out of place
- thomas777neo
- Forum Contributor
- Posts: 214
- Joined: Mon Mar 10, 2003 6:12 am
- Location: Johannesburg,South Africa
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
thomas777neo 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];
}PS: just learned classes about 5 minutes ago, so super hard-core technical answers will prob confuse me.
thnx all
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
php4 http://www.php.net/manual/en/language.o ... ructor.php
php5 http://www.php.net/manual/en/language.oop5.decon.php
php5 example:
php5 http://www.php.net/manual/en/language.oop5.decon.php
php5 example:
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];
}
//....
Last edited by Kieran Huggins on Thu Dec 28, 2006 2:50 pm, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
i'll assume your using php4
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);
//...
}
}