Current location: Hot Scripts Forums » Programming Languages » PHP » arrays, folders and more arrays


arrays, folders and more arrays

Reply
  #1 (permalink)  
Old 12-21-06, 12:41 AM
OnlineDesignz OnlineDesignz is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
arrays, folders and more arrays

hi,

I never normally need help with php but here goes.

I haved a array list full of file names from a folder.

If a user loads a page and the file name isn't in that array I want to print an error message. how can I do this?

thanks,
Joey.
Reply With Quote
  #2 (permalink)  
Old 12-21-06, 02:39 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Something like this?

PHP Code:



$page 
basename($_SERVER['PHP_SELF']);

if (!
in_array($page, array('page1.php''page2.php''page3.php''...')))
{
     exit(
'Bad request.');

Reply With Quote
  #3 (permalink)  
Old 01-01-07, 09:08 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I'd use this function:

http://us3.php.net/manual/en/function.file-exists.php

That way - you don't have to have an array of filenames - if the user tries to get a file that doesn't exist, you'll know.

This will also help if you forget to remove a filename from the array.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.