Jump to content

sfc

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by sfc

  1. Question 1) Is the only and proper way to call a parent function "parent::function()"? Are there other/better ways from within a child function? Question 2) What are the deciding factors for when to make a function or attribute static? How do you make that decision? Assuming 5.3... Thanks.
  2. That's what I did. I put it in the ini file. This is my first time running on a remote server so I'm not familiar with this.... Thanks!
  3. I don't understand how to use this function with my code. Do I put it in an include file for each page?
  4. Warning: require_once() [function.require-once]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/cernem5/public_html/includes/form_functions.php on line 2 I looked through all of the php.ini file and I can find this setting. Any suggestions? I contacted the guys at inmotion who are hosting my vps and they said they had to make a change on their server since I didn't have root access. Is there a way in my coding to avoid this problem? Here is the code that is causing all the problems: <?php echo date("Y", time()); ?>
  5. It is saying: 5.2.13 if I run it from my PHPEd IDE, which opens http://localhost:8080/file:/C:/wamp/www/xhtml-css/contact-us.php but if I type in http://localhost/xhtml-css/contact-us.php it says 5.3.1. Apparently I have something configured wrong. Is there a place we can move this so I can have someone help me understand what I am doing wrong? Thanks!
  6. I am running WAMP on windows 7 and PHP 5.3.1 and I am getting this error: Fatal error: Call to undefined function checkdnsrr() in C:\wamp\www\xhtml-css\includes\form_functions.php on line 80 According to the research I did checkdnsrr() was available on the Windows platform at 5.3 so why am I getting this? Here is where I make the call: if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) Any ideas?
  7. Figured it out...the code I copied had debug mode turned on...sorry for bothering you. Thanks for asking for the code...it made me go back through it.
  8. I'm getting a strange response using PHPMailer where it is echoing the gmail server responses. SMTP -> FROM SERVER:220 mx.google.com ESMTP e20sm5319142vcm.40 SMTP -> FROM SERVER: 250-mx.google.com at your service, [68.4.142.3] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH 250 ENHANCEDSTATUSCODES SMTP -> FROM SERVER:250 2.1.0 OK e20sm5319142vcm.40 SMTP -> FROM SERVER:250 2.1.5 OK e20sm5319142vcm.40 SMTP -> FROM SERVER:354 Go ahead e20sm5319142vcm.40 SMTP -> FROM SERVER:250 2.0.0 OK 1279116570 e20sm5319142vcm.40 I don't tell it to echo anything. Any ideas? Thanks
  9. I thought private methods couldn't be called by child classes and protected could but not by anything outside the class or sub-classes. Am I wrong?
  10. I haven't seen "!==" before. Isn't it suppose to be !=?
  11. So I am a little confused. The user class extends databaseobject so I should be able to call a protected class from the instantiated child right? i.e. $user->save(); Where save is protected method in the databaseobject class. But when I just did I got an error saying that I called a protected method. As soon as I change the save() method to public it worked perfectly. Can someone explain? Do you need more information? Thanks!
  12. Thanks guys...still wrapping my mind around all this.
  13. That's exactly what I want it to do. If I make the method static, will that change?
  14. If I have a class DatabaseObject that has the follow method: protected function attribute () { return get_object_vars($this); } And I call this method from the class user which extends the DatabaseObject class (i.e. $user->attribute), what will "$this" refer to? The parent or the child? Thanks!
  15. Is it safe to assume that this is the best/only way to do this?
  16. I want to set a static attribute to my log file path so it is accessible to all my functions. Is there a better way to do it? Thanks! <?php require_once(LIB_PATH."/".'initialize.php'); class logger { private static $file; function __construct() { logger::$file = SITE_ROOT . "/logs/log.txt"; } static function log_action($action="", $message = "") { global $session; $handle = fopen( logger::$file, 'at'); fwrite($handle, date("Y-m-d H:i:s"). "| ". $action . " " . $message. "\n"); fclose($handle); } // End of log_action() function static function log_exists() { if (!file_exists(logger::$file)) { } } // End of log_exists() function static function read_log() { } // End of read_log() function } // end of logger class $logger = new logger(); ?>
  17. So I thought I was cool but what do I do if I want the variable to be a class attribute that is usable by the rest of the functions in the class so I only have to load the path once? I tried this: <?php require_once(LIB_PATH."/".'initialize.php'); class logger { private static $file; function __construct() { static::$file = SITE_ROOT . "/logs/log.txt"; } static function log_action($action="", $message = "") { global $session; $handle = fopen( static::$file, 'at'); fwrite($handle, date("Y-m-d H:i:s"). "| ". $action . " " . $message. "\n"); fclose($handle); } // End of log_action() function static function log_exists() { if (!static::$file) { } } // End of log_exists() function static function read_log() { } // End of read_log() function } // end of logger class ?> But it didn't work, meaning that it didn't write to the file.
  18. Yes...I didn't notice that I dropped it into the function...that makes sense. Thanks...I'm starting to get my mind wrapped around this stuff.
  19. So I just did this: $file = SITE_ROOT . "/logs/log.txt"; like this: <?php require_once(LIB_PATH."/".'initialize.php'); class logger { static function log_action($action="", $message = "") { global $session; $file = SITE_ROOT . "/logs/log.txt"; $handle = fopen($file, 'at'); fwrite($handle, date("Y-m-d H:i:s"). "| ". $action . " " . $message. "\n"); fclose($handle); } } ?> I'm not clear on why this works. Why does $file = ... work but private static $file = SITE_ROOT . "/logs/log.txt"; doesn't? I understand what Cagecrawler posted...but what is the difference between the two variables. Clearly they are being defined differently but I'm not totally understanding how PHP views the two definitions. Thanks for your help.
  20. i figured out that I needed to define a variable outside of the class Like this: <?php require_once(LIB_PATH."/".'initialize.php'); $file = SITE_ROOT . "/logs/log.txt"; class logger { static function log_action($action="", $message = "") { global $session; global $file; $handle = fopen($file, 'at'); fwrite($handle, date("Y-m-d H:i:s"). "| ". $action . " " . $message. "\n"); fclose($handle); } } ?> But I don't understand why if I have defined a constant I can't use it in a class. Is there a way to do this because I would prefer to keep $file private. Thanks.
  21. Parse error: syntax error, unexpected '.', expecting ',' or ';' in C:\wamp\www\photo_gallery\includes\logger.php on line 6
  22. Thanks...sorry for the stupid miss. I do have another question: Why is this not working in my logger.php file? private static $file = SITE_ROOT . "/logs/log.txt"; In the initialize.php file I define SITE_ROOT as: defined('SITE_ROOT') ? null : define("SITE_ROOT", "/" . 'wamp' . "/". 'www' . "/" . 'photo_gallery' ); Thanks
  23. I am very much in the learning process of PHP and programming in general. I have a feeling if I get this concept I will be well on my way so your help is greatly appreciated. I want to write a line to my "log.txt" file whenever someone logs in. Can you help me figure out what I am doing wrong? This is all experimental and is not heading for production, at least not for a long time. Here is the error I am getting: Notice: Undefined variable: user_id in C:\wamp\www\photo_gallery\includes\session.php on line 25 Fatal error: Cannot access empty property in C:\wamp\www\photo_gallery\includes\session.php on line 25 Here is the login.php file: <?php require_once("../../includes/initialize.php"); if($session->is_logged_in()) { redirect_to("index.php"); } //Check to see if page was submitted if(isset($_POST['submit'])) { $username = trim($_POST['username']); $password = trim($_POST['password']); //Check database to see if username/password exist. $found_user = User::authenticate($username, $password); if($found_user) { $session->login($found_user); //header("Location: index.php"); } else { $message = "Username/password combination incorrect."; } } else { $username = ""; $password = ""; } ?> <html> <head> <link href="../stylesheets/main.css" media="all" rel="stylesheet" type="text/css" /> <title>Photo Gallery</title> </head> <body> <div id="header"> <h1>Photo Gallery</h1> </div> <div id="main"> <h2>Staff Login</h2> <?php echo output_message($message)?> <form action="login.php" method="post"> <table> <tr> <td>Username:</td> <td> <input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /> </td> </tr> <tr> <td>Password:</td> <td> <input type="password" name="password" maxlength="30" value="<?php htmlentities($password); ?>" /> </td> </tr> <tr> <td colspan="2"> <input type="submit" name="submit" value="Login" /> </td> </tr> </table> </form> </div> <div id="footer"> Copyright <?php echo date("Y", time()); ?> </div> </body> </html> <?php if(isset($database)) { $database->close_connection();} ?> Here is the initialize.php: <?php defined('SITE_ROOT') ? null : define('SITE_ROOT', "/" . 'wamp' . "/". 'www' . "/" . 'photo_gallery' ); defined('LIB_PATH') ? null : define ('LIB_PATH', SITE_ROOT . "/" . 'includes'); require_once(LIB_PATH."/"."config.php"); require_once(LIB_PATH."/"."functions.php"); require_once(LIB_PATH."/"."session.php"); require_once(LIB_PATH."/"."database.php"); require_once(LIB_PATH."/"."database_object.php"); require_once(LIB_PATH."/"."user.php"); require_once(LIB_PATH."/"."logger.php"); ?> Here is the user.php: <?php // If it's going to need the database, then it's // probably smart to require it before we start. require_once(LIB_PATH."/".'database.php'); class User extends DatabaseObject { public $id; public $username; public $password; public $first_name; public $last_name; public function full_name() { if(isset($this->first_name) && isset($this->last_name)) { return $this->first_name . " " . $this->last_name; } else { return ""; } } public static function authenticate($username="", $password="") { global $database; $username = $database->escape_value($username); $password = $database->escape_value($password); $sql = "SELECT * FROM users "; $sql .= "WHERE username = '{$username}' "; $sql .= "AND password = '{$password}' "; $sql .= "LIMIT 1"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } } ?> Here is the session.php: <?php require_once("logger.php"); // A class to help work with Sessions // In our case, primarily to manage logging users in and out // Keep in mind when working with sessions that it is generally // inadvisable to store DB-related objects in sessions class Session { private $logged_in=false; public $user_id; function __construct() { session_start(); $this->check_login(); if($this->logged_in) { // actions to take right away if user is logged in } else { // actions to take right away if user is not logged in } } public function return_userid() { return $this->$user_id; } public function is_logged_in() { return $this->logged_in; } public function login($user) { // database should find user based on username/password if($user){ $this->user_id = $_SESSION['user_id'] = $user->id; $this->logged_in = true; logger::log_action("logged in"); } } public function logout() { unset($_SESSION['user_id']); unset($this->user_id); $this->logged_in = false; } private function check_login() { if(isset($_SESSION['user_id'])) { $this->user_id = $_SESSION['user_id']; $this->logged_in = true; } else { unset($this->user_id); $this->logged_in = false; } } } $session = new Session(); ?> Here is the logger.php: <?php (LIB_PATH."/".'session.php'); class logger { private static $file = "/wamp/www/photo_gallery/logs/log.txt"; static function log_action($action="", $message = "") { global $session; $handle = fopen(logger::$file, 'at'); fwrite($handle, date("Y-m-d H:i:s"). "| Login: " . $session->return_userid() . " " . $action. "\n"); fclose($handle); } } ?>
  24. Thanks guys! That makes a lot of sense. I'll try that out.
  25. If you go on the php.net site and look up the function mail...you should find what you are looking for.
×
×
  • Create New...

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.