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 Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.