homepage Welcome to WebmasterWorld Guest from 54.234.231.49
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & eelixduppy & jatar k

PHP Server Side Scripting Forum

    
Are checking $ SERVER variables server intensive?
How inefficient is this code?
suga




msg:4349187
 8:42 pm on Aug 8, 2011 (gmt 0)

I have a sidebar on each page of my site that needs to be wider or narrower depending on where you are on my site. Currently, I have this line of code in the header of each page:

if ($_SERVER[SCRIPT_NAME] == "/index.php")
$width = $homepagewidth;
else if (strstr($_SERVER['SCRIPT_NAME'],"forum"))
$width = $forumwidth;
else
$width = $restofsitewidth;

Is it inefficient to check the SCRIPT_NAME variable on each and every page?

Thanks.

 

penders




msg:4349429
 11:36 am on Aug 9, 2011 (gmt 0)

As far as I'm aware, checking the $_SERVER superglobal is just like checking any other variable so in that sense I don't think you can really get anymore efficient.

brotherhood of LAN




msg:4349432
 11:40 am on Aug 9, 2011 (gmt 0)

The variables are already present and as penders says, it's just like calling regular variables.

You might be able to optimize the if/else statement though. If you found that 'forum' was getting accessed more frequently than '/index.php' you could put 'forum' at the top of the if/else statement.

suga




msg:4349694
 10:46 pm on Aug 9, 2011 (gmt 0)

thank you both!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved