JSHINER Posted September 20, 2006 Share Posted September 20, 2006 Hello,I'm new to these forums, and pretty new to PHP, but I have a basic understanding.My question:I currently have the include:@ include("ma/$zip/1.php");The $zip is from a form field at the beginning. So when you put in your zip, it pulls up the appropriate zip page. If a zip code page DOES NO EXIST, I want a message to come up. I currently have the @ there so nothing comes up, but it does not look right. I want a page to come up that says it does not exist. Any help would be much appreciated.Thanks,James Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/ Share on other sites More sharing options...
wildteen88 Posted September 20, 2006 Share Posted September 20, 2006 Prehaps check that the file exists first, by using file_exists before including it like this:[code=php:0]if(file_exists("ma/$zip/1.php")){ include("ma/$zip/1.php");}else{ echo "Sorry that Zip Code does not exist. Please try again";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-95495 Share on other sites More sharing options...
JSHINER Posted September 20, 2006 Author Share Posted September 20, 2006 Thank you! Worked perfect. Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-95505 Share on other sites More sharing options...
Daniel0 Posted September 20, 2006 Share Posted September 20, 2006 If the variable $zip comes from user input, make sure you secure it so people don't do malicious things. Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-95562 Share on other sites More sharing options...
JSHINER Posted September 20, 2006 Author Share Posted September 20, 2006 How can I secure it? Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-95660 Share on other sites More sharing options...
JSHINER Posted September 21, 2006 Author Share Posted September 21, 2006 Could someone please point me in the right direction towards securing this ? Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-96003 Share on other sites More sharing options...
wildteen88 Posted September 21, 2006 Share Posted September 21, 2006 What I think Dan means is to valid the zipcode the user provides. For example checking that the zipocode is in the correct format and is valid. You can do this using regular expressions and using a function called preg_match. Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-96095 Share on other sites More sharing options...
JSHINER Posted September 21, 2006 Author Share Posted September 21, 2006 Oh... OK. Yes I actually did that already, and infact I found the code on this site. It only accepts valid zip codes. If they're not valid it kicks back an error and asks for a valid one. Quote Link to comment https://forums.phpfreaks.com/topic/21436-include-question/#findComment-96127 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.