NYCPHP Meetup

NYPHP.org

PHP can't access files (but TCL can!!!)

Phil Powell soazine at erols.com
Sat May 11 17:52:31 EDT 2002


TCL 1, PHP 0

Ok, I am frustrated.. here is my code and this portion has to be done in
PHP.  I have a frame that can only be accessed if 1 of 2 things occur:

1) if $HTTP_REFERER has a specific value
2) if your nickname passed in the query string is found in the existing
nicknames.txt file found in /chat/nicknames.txt

Here is the code:

<?
 // Security measure to prevent bookmarking of page unless nickname exists
in nicknames.txt
 $contents = "";
 if (!preg_match("/\\bchat_process_nickname\\b/i", $HTTP_REFERER)) {
  $canAccessChatroom = 1;
  if (strlen($nickname) < 2) $canAccessChatroom = 0;
  if (!file_exists($DOCUMENT_ROOT . "/chat/nicknames.txt"))
$canAccessChatroom = 0;
  if ($canAccessChatroom == 1) {
   $fileID = fopen($DOCUMENT_ROOT. "/chat/nicknames.txt", r) or die ("could
not open file");
   if (!$fileID) {
    $canAccessChatroom = 0;
   } else {
    $contents = fread($fileID);
    fclose($fileID);
   }
  }
  if ($canAccessChatroom == 1 && strlen($contents) == 0) $canAccessChatroom
= 0;
  if ($canAccessChatroom == 1 && !preg_match("/[a-zA-Z0-9_\\-]+/",
$contents)) $canAccessChatroom == 0;
  if ($canAccessChatroom == 1) {
   if (!preg_match("/\\b$nickname\\b/i", $contents)) $canAccessChatroom == 0;
  }
  if ($canAccessChatroom == 0) {
   echo "<meta http-equiv=Refresh content='1;URL=http://" . $SERVER_NAME .
"/chat/chat_login.php'>\
";
   echo "<script>\
<!--\
  location.href='http://" . $SERVER_NAME .
"/chat/chat_login.php';\
\\/\\/-->\
</script>\
";
  }
 }
?>

No matter what I do, however, the file cannot be accessed if it exists and
causes damage galore.  Can anyone out there help me figure out what I did
wrong; I'm completely stumped and may have to rewrite this portion of the
chatroom in TCL, all of my TCL scripts have had NO problems whatsoever
accessing the txt files.

Phil




More information about the talk mailing list