Jump to content

Archived

This topic is now archived and is closed to further replies.

JSHINER

INCLUDE QUESTION

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
If the variable $zip comes from user input, make sure you secure it so people don't do malicious things.

Share this post


Link to post
Share on other sites
Could someone please point me in the right direction towards securing this ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.