FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php error ?[parse error]





siena
Can you tell me why this script error...
Code:
<?php
     # ip deny class
     # author S.V.Sudharshan. 01/04/2001
     # improved from Simple IP Deny v 3.0 (previous by Robbo)
     # see revision notes below for changes.

     # ***REVISION 4.01***
     # This code was revised by mikkoeerola@hotmail.com 08/27/2001
     # Revision Changes:
     # 1. If denyList is empty, ip check will be skipped
     # 2. Fixed errortime reporting, earlier version displayed hours and minutes
     #    with only 1 digit, eg. 2:3 (14:03). Got rid of unnecessary errortime code
     #    and used date() function instead.

class IP_Deny {
  var $classname = "IP_Deny";
  var $denyList = "";
  var $notify = 1;
  var $respond = 1;
  var $denyMsg = "Server fail";
  var $emailaddress = getenv("SERVER_ADMIN");
  var $remote_ip = getenv("REMOTE_ADDR");
  var $docroot = getenv("SERVER_NAME");
  var $denied = 0;

  function send_email(){
   # Request access to the global variables we need
   global $REQUEST_URI;

   # Build the $errortime variable to contain the date/time of the error.
   $errortime = date("D M j Y G:i:s T");

   # Create email subject and propaganda =) for the notify email
   $email_subject = "Access attempt from $this->remote_ip";

   # Create the body of the email message
   $message = "IP $this->remote_ip tried to access $this->docroot$REQUEST_URI on your server on $errortime.\n\n";

   # Send the mail message. This assumes mail() will work on your system!
   mail("$this->emailaddress", $email_subject, $message, "From: $this->emailaddress");
   return;
  }
  # send_email function end.
 
  function probe(){
      # if the denied IP == remote IP
      if ($this->denyList != "") {

      if(ereg("^($this->denyList)",$this->remote_ip)){
        $this->denied = 1;
     
        if ($this->notify == 1 ) $this->send_email();
        if ($this->respond == 1) {
          echo '
          <html>
          <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>
          <body>
          <!-- Error -->
        <font name="Arial">';
          echo $this->denyMsg;
          echo '</font>
        </body>
          </html>';
        }
      }
    }
  }
  # probe function end.
}
# class definition end.
?>


when I try this script i read some message
Quote:
Parse error: parse error, unexpected '(', expecting ',' or ';' in c:\xampp\htdocs\test.php on line 21
Kaneda
These lines:

Code:

  var $emailaddress = getenv("SERVER_ADMIN");
  var $remote_ip = getenv("REMOTE_ADDR");
  var $docroot = getenv("SERVER_NAME");


In PHP 4, you can't initialize class member variables with anything but constants - so, you're not allowed to call a function there. If you need to initialize using a function, you have to call that function in the constructor. I.e., change it to this:

Code:

  var $emailaddress;
  var $remote_ip;
  var $docroot;


... and add the constructor:

Code:

  function IP_Deny() {
    $this->emailaddress =  getenv("SERVER_ADMIN");
    $this->remote_ip = getenv("REMOTE_ADDR");
    $this->docroot = getenv("SERVER_NAME");
  }
siena
when I try your code... I can see error, but
why I don't see anything (like message)
this is my code :
Code:
<?php
     # ip deny class
     # author S.V.Sudharshan. 01/04/2001
     # improved from Simple IP Deny v 3.0 (previous by Robbo)
     # see revision notes below for changes.

     # ***REVISION 4.01***
     # This code was revised by mikkoeerola@hotmail.com 08/27/2001
     # Revision Changes:
     # 1. If denyList is empty, ip check will be skipped
     # 2. Fixed errortime reporting, earlier version displayed hours and minutes
     #    with only 1 digit, eg. 2:3 (14:03). Got rid of unnecessary errortime code
     #    and used date() function instead.

class IP_Deny {
  var $classname = "IP_Deny";
  var $denyList = "localhost,172.17.100.155";
  var $notify = 1;
  var $respond = 1;
  var $denyMsg = "Server fail";
  var $emailaddress;
  var $remote_ip;
  var $docroot;
  var $denied = 0;

  function send_email(){
   # Request access to the global variables we need
   global $REQUEST_URI;

   # Build the $errortime variable to contain the date/time of the error.
   $errortime = date("D M j Y G:i:s T");

   # Create email subject and propaganda =) for the notify email
   $email_subject = "Access attempt from $this->remote_ip";

   # Create the body of the email message
   $message = "IP $this->remote_ip tried to access $this->docroot$REQUEST_URI on your server on $errortime.\n\n";

   # Send the mail message. This assumes mail() will work on your system!
   mail("$this->emailaddress", $email_subject, $message, "From: $this->emailaddress");
   return;
  }
  # send_email function end.
 
  function probe(){
      # if the denied IP == remote IP
      if ($this->denyList != "") {

      if(ereg("^($this->denyList)",$this->remote_ip)){
        $this->denied = 1;
     
        if ($this->notify == 1 ) $this->send_email();
        if ($this->respond == 1) {
          echo '
          <html>
          <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>
          <body>
          <!-- Error -->
        <font name="Arial">';
          echo $this->denyMsg;
          echo '</font>
        </body>
          </html>';
        }
      }
    }
  }
  # probe function end.
  function IP_Deny() {
    $this->emailaddress =  getenv("SERVER_ADMIN");
    $this->remote_ip = getenv("REMOTE_ADDR");
    $this->docroot = getenv("SERVER_NAME");
  }
 }
# class definition end.

?>

thank for your comment...
Ducksteina
siena wrote:
when I try your code... I can see error, but
why I don't see anything (like message)
this is my code :
Code:
<?php
     # ip deny class
     # author S.V.Sudharshan. 01/04/2001
     # improved from Simple IP Deny v 3.0 (previous by Robbo)
     # see revision notes below for changes.

     # ***REVISION 4.01***
     # This code was revised by mikkoeerola@hotmail.com 08/27/2001
     # Revision Changes:
     # 1. If denyList is empty, ip check will be skipped
     # 2. Fixed errortime reporting, earlier version displayed hours and minutes
     #    with only 1 digit, eg. 2:3 (14:03). Got rid of unnecessary errortime code
     #    and used date() function instead.

class IP_Deny {
  var $classname = "IP_Deny";
  var $denyList = "localhost,172.17.100.155";
  var $notify = 1;
  var $respond = 1;
  var $denyMsg = "Server fail";
  var $emailaddress;
  var $remote_ip;
  var $docroot;
  var $denied = 0;

  function send_email(){
   # Request access to the global variables we need
   global $REQUEST_URI;

   # Build the $errortime variable to contain the date/time of the error.
   $errortime = date("D M j Y G:i:s T");

   # Create email subject and propaganda =) for the notify email
   $email_subject = "Access attempt from $this->remote_ip";

   # Create the body of the email message
   $message = "IP $this->remote_ip tried to access $this->docroot$REQUEST_URI on your server on $errortime.\n\n";

   # Send the mail message. This assumes mail() will work on your system!
   mail("$this->emailaddress", $email_subject, $message, "From: $this->emailaddress");
   return;
  }
  # send_email function end.
 
  function probe(){
      # if the denied IP == remote IP
      if ($this->denyList != "") {

      if(ereg("^($this->denyList)",$this->remote_ip)){
        $this->denied = 1;
     
        if ($this->notify == 1 ) $this->send_email();
        if ($this->respond == 1) {
          echo '
          <html>
          <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          </head>
          <body>
          <!-- Error -->
        <font name="Arial">';
          echo $this->denyMsg;
          echo '</font>
        </body>
          </html>';
        }
      }
    }
  }
  # probe function end.
  function IP_Deny() {
    $this->emailaddress =  getenv("SERVER_ADMIN");
    $this->remote_ip = getenv("REMOTE_ADDR");
    $this->docroot = getenv("SERVER_NAME");
  }
 }
# class definition end.

?>

thank for your comment...

You are creating a class and functions, but you are not using them. You need to use the class to make it work. Wink
siena
Ducksteina wrote:
You are creating a class and functions, but you are not using them. You need to use the class to make it work. Wink

Can you give me some example.....?
Related topics
error with cash mod
Fatal PHP error
uma grande dúvida em php, por favor me ajudem
[PHP] Error link
PHP/Blogger error
Need help with php script
need some help - php switch code
Impossible parse error!
Try method in php does not work
Parse error - need help
PHP - Error
PHP Error Pages
Parse error: syntax error, unexpected T_NEW
XML/XHTML header problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.