Jagand Posted September 25, 2010 Share Posted September 25, 2010 Hi, I am writing a little code that would populate the server name based on $_SERVER['HTTP_HOST']. My code and the error I encounter are given below. Can we ever use $_SERVER in a class? class Get_server_name { if ($_SERVER['HTTP_HOST'] == 'localhost'): $hostname = 'localhost'; else: $hostname = 'my remote server'; endif; } Error I get: Parse error: parse error, expecting `T_FUNCTION' in Link to comment https://forums.phpfreaks.com/topic/214370-_server-details-in-a-class/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 Perhaps you are trying to write a function? You cannot just put lines of code inside of a class definition. Code would need to be inside of a method/function definition inside of a class definition. Link to comment https://forums.phpfreaks.com/topic/214370-_server-details-in-a-class/#findComment-1115554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.