Jump to content


Photo

INCLUDE QUESTION


  • Please log in to reply
7 replies to this topic

#1 JSHINER

JSHINER
  • Members
  • PipPipPip
  • Advanced Member
  • 465 posts
  • LocationBoston, MA

Posted 20 September 2006 - 04:34 PM

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 September 2006 - 04:39 PM

Prehaps check that the file exists first, by using file_exists before including it like this:
if(file_exists("ma/$zip/1.php"))
{
    include("ma/$zip/1.php");
}
else
{
    echo "Sorry that Zip Code does not exist. Please try again";
}


#3 JSHINER

JSHINER
  • Members
  • PipPipPip
  • Advanced Member
  • 465 posts
  • LocationBoston, MA

Posted 20 September 2006 - 04:50 PM

Thank you! Worked perfect.

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 September 2006 - 05:47 PM

If the variable $zip comes from user input, make sure you secure it so people don't do malicious things.

#5 JSHINER

JSHINER
  • Members
  • PipPipPip
  • Advanced Member
  • 465 posts
  • LocationBoston, MA

Posted 20 September 2006 - 08:33 PM

How can I secure it?

#6 JSHINER

JSHINER
  • Members
  • PipPipPip
  • Advanced Member
  • 465 posts
  • LocationBoston, MA

Posted 21 September 2006 - 12:14 PM

Could someone please point me in the right direction towards securing this ?

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 September 2006 - 02:14 PM

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.

#8 JSHINER

JSHINER
  • Members
  • PipPipPip
  • Advanced Member
  • 465 posts
  • LocationBoston, MA

Posted 21 September 2006 - 03:15 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users