Jessica Posted February 24, 2007 Share Posted February 24, 2007 What I've got works, but I'm concerned about the fact that the only reason the file wouldn't exist is if the user messed with the url. ($in is a url variable, properly sanitized, etc.). I don't want users to see "Warning: require_once(xxx) [function.require-once]: failed to open stream: etc, etc." if they're just poking around and messing with the url, but it seems like such overkill to check every time if the file exists when most of the time it will. There's probably a better way to do this...thoughts? <?php if(file_exists($in.'.php')){ require_once($in.'.php')){ }else{ print 'Woops!'; }?> Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 24, 2007 Share Posted February 24, 2007 typing a function name at the top of each page is alot better than typing that I'd put it in a function and just call the function when its needed. I always use include or include_once so no errors show up if something happens that the file isn't there, but then again im still learning PHP lol Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Author Share Posted February 24, 2007 That's only on one page, my base.php file which includes the other stuff, it's not on every page literally. I'm not talking about lines of code, but rather code efficiency. Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 24, 2007 Share Posted February 24, 2007 This might be worse, if not exactly the same, but you could store an array of the file names and check it off the array instead of using the file_exists function. I can't imagine that being any different, thought, as it does the exact same thing. If you use the URL method, you gotta assume the user is an idiot, and expect for them to play with everything they possibly can. I guess that would be the downfall to using the URL to pass the $in variable, but you are well aware of that, I'm sure. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Author Share Posted February 24, 2007 I'd have to be constantly updating the array then...that would get annoying fast Thanks for the idea though Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted February 24, 2007 Share Posted February 24, 2007 file_exists is actually pretty slow, I've run into issues with it before. I like the idea of a LUT, as JBS suggested. Best, Patrick Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 24, 2007 Share Posted February 24, 2007 Just a note: I'm not sure if you are aware of is_file(), but it seems (and I'm not positive) to be a slightly faster alternative. It also won't return true for directories like file_exists would. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Author Share Posted February 24, 2007 good idea JBS, thanks. I guess I will switch it to an error surpressed include for now and not check if the file exists. That way if they try to mess with it the most they'll get is a blank page :/ Quote Link to comment 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.