Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by benanamen

  1. Is the manual example a bad usage? Question was regarding the autoloader. I want to know it inside and out before I go on the the next item.
  2. RE: spl_autoload_register I am using the example code from the manual and it works. spl_autoload_register(function ($class) { include 'classes/' . $class . '.class.php'; }); $valid_login = new LoginAttemptsLog($pdo); $valid_login->logSuccessfulAttempt('new_goodusername'); Through testing I see that it somehow reads new LoginAttemptsLog into $class and thinks it is a filename to look for in the classes directory. Do I need to understand anything more than this? What else is there to know about this?
  3. I will just say, you have at least fifty percent more code than you need.
  4. You are missing a where clause. Your query is selecting all of the usernames and passwords in the whole database. Your whole code is flawed. I'm sure others will give you more feedback.
  5. Works for me.
  6. Just making a suggestion as this is what this forum is for. Not looking to get into an argument about it. Probably because there is no specific forum for it. Now you're getting ridiculous. This site has NUMEROUS SPECIFIC forums that are not php. Javascript Help, Html Help, CSS Help,........... And if I was already at the rails forum I probably would if there were knowledgeable people there. benanamen, on 07 Oct 2016 - 11:29 AM, said: Reductio ad absurdum Whatever your trying to say here, the rails forum you link to is exactly that. Rails and other. This is not a pure php site like the rails site is pure rails.
  7. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ // process form } ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> <!-- FORM HERE --> </form> </body> </html>
  8. Umm, could it be your trying to run PHP as Javascript?
  9. "Other" is pretty generic and does not group the topic types. This site may as well just have a php forum and other forum only then. It takes a couple seconds for a mod to add a specific forum so what will it hurt to add it, popular or not? I currently leave this site to other forums for the "other" technology stuff. The first top two priorities for a site owner is to get people to their site and to keep them there. IMO, phpfreaks has the most knowledgeable experts than any other forums I am on.
  10. You have my vote as well as for other technologies. I posted to Comments https://forums.phpfreaks.com/topic/302292-new-forums/
  11. I would like to propose that new specific forums are added to this site for Ruby/Rails, Python and Java and perhaps others. (Yeah, I know it's "PHP Freaks"). It would be beneficial to this site and its users. It is also common on other coding sites to cover all the various technologies.
  12. Am I better off heading straight to ruby first? Does ruby knowledge transfer over to Php OOP? Are you on any ruby help forums?
  13. When extending the class, does it matter if you do classname::method or if you do parent::method? Is there a best practice on this?
  14. That answers an upcoming question I had. With all these classes in an app, how do you know how to use them. That is the problem I am going to run into until I get this down. I wouldnt know bad OOP staring me in the face. Any OOP tutorial recommendations? This is worth it's weight in gold! When you explain things the way you just did I can get a good grasp of it. All the tutorials I have seen don't really explain in detail. They just say do this, do that. So, if I understand correctly I don't want to do protected $username =""; right?
  15. So now this tutorial I am studying uses another example and the same type of line previously asked about equals an empty string public $username = "";. I tried it without the empty string like public $username; and it still works. What is there to know about this? Any recommendations that give detailed explanations of the code? * Edit, now elsewhere I am also seeing var $some_variable; for the same type of line. So there is Public, Private, Protected and Var? OOP is making my head hurt. <?php class Member { public $username = ""; } $member = new Member(); $member->username = "Fred"; echo $member->username; ?>
  16. Appreciate the response, but when it comes to OOP I need answers really dumbed down until I get a grasp of this. I want to understand why to do things and not just do it because it works. How does it do that? How do you avoid it? By having the line in question? Would that line generally be public or private? Is it just because you won't get documentation or are their more reasons? Is their any special name for a property with no value like the line mentioned? Lost me here. I looked up code completion and it seems to only apply to IDE's and thus far is the only place I have been aware of it. The rest is russian to me so far.
  17. In the following class, it works with or without line 4 public $num. So why is it there? <?php class mathematics { public $num; public function addTwo() { return $this->num + 2; } } $math = new mathematics; $math->num = 3; echo $math->addTwo(); ?>
  18. So now I have some classes that need to be used by the application. From what I can gather, now I need to know several things to "include" them in the app such as Namespaces, spl_autoload_register, and PSR-4. Could someone please put these things in perspective and when/how to implement. I have read up on each of these items. I am not grasping it as of now. It also seems to be that their is a particular directory structure for the class files and not just a single directory with all the class files in it.
  19. Thanks @Jaques1. I don't know the pros/cons between what you posted and what @kicken posted. Is it an either one will work or is one better than the other for some reason?
  20. Oh, I very much get that. As the link you referenced starts "Our client has come up with the requirement that". As I said, this is just for practicing OOP right now and was old procedural code from long, long ago. The class as you have modified it is very clean now. I will just remove the password storage and it should be good to go. More importantly, I just picked up a couple more tidbits of OOP knowledge which was the purpose of doing this in OOP. Thanks!
  21. Currently it does. It should be logging Bad Username/Bad Password and Valid username/Bad password. I know right now it will also do the undesired bad username/good password which is a fail since a good pass is in plain text. This started from an old procedural login code and right now is just for learning OOP. The idea was to see when a login fails, what was entered when it failed. * Edit: Original code did not log good password in plain text. I see what you did with the PDO type declaration. I never would have got that from the Manual. Does that fall under the self type on the man page linked to? Agree with your class name suggestion I could see that it was near duplicate code and figured that was an area that could be improved. With that said I don't understand how to implement what you just said. I do get the gist of it, but implementing in OOP I am lost at the moment. I still have less than 24 hours into serious OOP study.
  22. I was practicing OOP and made a simple class to log logins. Does anyone see any problems with this or improvements that can be made? Any issue with using NOW() in the query string instead of a placeholder? In another thread, @Jaques1 said: How would I implement that? I rtfm and don't understand it as of yet. <?php // ---------------------------------------------------------------------------- // Database Connection // ---------------------------------------------------------------------------- $dbhost = 'localhost'; $dbname = 'test'; $dbuser = 'root'; $dbpass = ''; $charset = 'utf8'; $dsn = "mysql:host=$dbhost;dbname=$dbname;charset=$charset"; $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO($dsn, $dbuser, $dbpass, $opt); //------------------------------------------------------------------------ // //------------------------------------------------------------------------ $valid_login = new LogLoginStatus($pdo); $valid_login->validLogin('goodusername'); $invalid_login = new LogLoginStatus($pdo); $invalid_login->invalidLogin('bad_username', 'bad_password'); //------------------------------------------------------------------------ // //------------------------------------------------------------------------ class LogLoginStatus { /** * Log Valid/Invalid logins * * @param string login_username * @param string login_password */ public function __construct($pdo) { $this->pdo = $pdo; } function validLogin($username) { $sql = "INSERT INTO user_login (login_status, login_ip, login_username,login_password, login_datetime) values(?, INET_ATON(?), ?, ?, NOW())"; $stmt = $this->pdo->prepare($sql); $stmt->execute(array( 1, $_SERVER['REMOTE_ADDR'], $username, '***' )); } function invalidLogin($username, $password) { $sql = "INSERT INTO user_login (login_status, login_ip, login_username,login_password, login_datetime) values(?, INET_ATON(?), ?, ?, NOW())"; $stmt = $this->pdo->prepare($sql); $stmt->execute(array( 0, $_SERVER['REMOTE_ADDR'], $username, $password )); } } ?> CREATE TABLE `user_login` ( `login_id` int(11) NOT NULL AUTO_INCREMENT, `login_status` tinyint(1) DEFAULT NULL, `login_ip` int(10) unsigned DEFAULT NULL, `login_username` varchar(255) DEFAULT NULL, `login_password` varchar(255) DEFAULT NULL, `login_datetime` datetime DEFAULT NULL, PRIMARY KEY (`login_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  23. The OP said PHP magically generates HTML which it does not.
  24. Really? Show me where the html is here: <?= 'Hello World' ?>
  25. When I click the quote icon there is no new line. It is a single line which is how I would expect for it to remain when I click post, but it adds in a line after clicking post. While we are at it. There is another longstanding problem I have had. There is no way for me to add attachments. I can click my media and select something that I somehow was able to attach at one point in time. I can't add anything new.
×
×
  • 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.