Re: Whats wrong with my code?

From: Date: Wed, 17 Sep 2003 13:15:07 +0000
Subject: Re: Whats wrong with my code?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-162862@lists.php.net to get a copy of this message
Stevie -- You've already been beaten up about posting tons of code, so I won't add to that (much, anyway; DON'T, and ABSOLUTELY DON'T 'TOFU' POST!). And you've heard that you needed the ; on the last line and to correct your occasional $includes problems, so that's done. Yes, you should work on reducing the problem to its minimum cause. While a default case is not required for a switch statement, you could have the same problem by replacing all of those cases with a default -- and then you not only might find the answer yourself but you also wouldn't take so much heat for posting so much junk :-) You should also read the manual to see how to use include(). I'll bet a twinkie that /includes doesn't exist on your server (who would give a web site access to files right off of the system root directory??) but am not going to tell you any more because you should go and look it up yourself. No, this reply is more about style and tricks. Your code is long and difficult to debug because of its sheer bulk, and it needn't be. I would write your entire 200 (or 151) lines of code as <?php $page = $_GET['id'] ; if ( is_file("/includes/$page.html") ) { include("/includes/$page.html") ; } ?> if you didn't need to exclude any possibilities or, much more sanely, <?php $includes = array ( "home", "arts", ... "world") ; $page = $_GET['id'] ; if ( in_array($page,$includes) && is_file("/includes/$page.html") ) { include("/includes/$page.html") ; } ?> (just from the top of my head, though, without real thought for security) and in reality I'd probably not bother with the $page temp variable. Good luck, and enjoy :-) HTH & HAND :-D -- David T-G * There is too much animal courage in (play) davidtg@justpickone.org * society and not sufficient moral courage. (work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

« previous php.general (#162862) next »