Jump to content

Jacques1

Members
  • Posts

    4,207
  • Joined

  • Last visited

  • Days Won

    209

Everything posted by Jacques1

  1. And you want to connect that to the Internet? A machine with 12-year-old software that hasn't seen a security update ever since?
  2. The problem is that you don't really seem to understand basic programming concepts (like methods) and terminology. This makes it very difficult to figure out what you're trying to do, let alone fix the actual code. I strongly recommend that you learn the basics before you try to write any complex code. The PHP manual may be a good starting point.
  3. The entire method makes no sense. You have 9 parameters, you use 2, and you want none. Um, what? At the same time you're pulling variables out of nowhere. Where is $atividade coming from? What is $local? Are those supposed to be properties, i. e. $this->atividade and $this->local?
  4. Neither. A setter assigns a new value to a property and typically starts with “set...”, a getter retrieves the value of a property and typically starts with “get...” (or “is...” for boolean properties). This doesn't apply to any of the methods you've mentioned. As a better example: A User instance might have a User::setEmailAddress($newAddress) setter and a User::getEmailAddress() getter. The setter sets the e-mail address, the getter gets it (just like the names say). If you have a setter, that implies you don't want the property to be public. That's the whole point of getters and setters: They allow controlled access to a private or protected property. So either the property is public and may be changed to anything by anyone, in which case you don't need getters and setters. Or the property is non-public, in which case getters and (if needed) setters are simply a requirement. It typically doesn't return anything. But nobody prevents you from returning $this (e. g. for the sake of a Fluent Interface).
  5. Please, no more meaningless fantasy code. You've already acknowledged that your abstract examples aren't helpful and lead to a lot of misunderstands, yet you keep making them up. Nobody expects you to upload your entire project, but we do need more than “MyObj” and “stuff” to make an informed decision. Deciding between a single getter and multiple getters depends on how the data is related. This question is unanswerable when the “data” is “a”, “b” and “c”. With this little info, all I can say is that the setStuff() method makes no sense. Methods beginning with “set” are supposed to actually set a new value from external data. But your “setter” is really a weird implementation of a getter.
  6. Your send_mail() function has no protection against mail header injection. The above code with mostly hard-coded arguments may not be vulnerable, but that's just a happy coincidence. As soon as you have to deal with dynamic input, you will run into security problems. Using the low-level mail() function is generally a bad idea, because it's far too dangerous and error-prone. You should use a proper library like PHPMailer instead. This code makes no sense. A HMAC is a message authentication code used to protect data from manipulation. You don't have this kind of data. And the third argument must be a (binary) cryptographic key, not a simple name. I'm surprised that PHP even accepts that input. Neither hashes nor HMACs make sense in this context. You need to generate a binary random number and then encode it to make it human readable. A hash is only used to safely store the random number. So the procedure is as follows: generate random bytes encode the random bytes (hex-encoding is usually the most robust variant) and send the encoded token in an e-mail hash the raw random bytes and store the hash in the database; a simple SHA-256 hash is enough in this case, because random bytes cannot easily be brute-forced like a password from a human user
  7. Without the exact code, it's hard to tell what's wrong. Is the URL shortener script publicly available? HTML entities like & in the wrong places are often caused by poorly written code which blindly applies htmlspecialchars() or htmlentities() to all input “to make it secure”. That's what you could search for. Besides that, we can only speculate. By the way, your own code should apply HTML-escaping to the URL before it's printed so that ampersands appear as & in the HTML source. Otherwise you may run into syntax conflicts or even security vulnerabilities.
  8. It's considered good practice, simply because it's both nice to read and nice to write. There's even a design pattern for it: The Fluent Interface. The only reason why PDO isn't fluent is that it supports legacy error handling and uses the return values to indicate errors. Without this baggage, I'm sure our code would look exactly as you suggested (including the formatting).
  9. "Not working" is terribly unspecific. What's the exact output of wget?
  10. The values are correct. display_errors must be 1, error_reporting must be E_ALL. E_ALL can optionally be replaced with -1, but this is an obsolete workaround for early PHP versions where E_ALL didn't actually mean “all errors”. Since PHP 5.4, E_ALL does exactly what it says.
  11. // Moved from JavaScript forum Whatever language that is, it's not JavaScript. Are you confusing Java and JavaScript? Those are two entirely different languagues not related in any way. If you do mean Java, your question still makes no sense to me, because you've already answered it yourself: System.out.print(car); This does exactly what it says. It prints the name of the enum constant.
  12. You need to do it in the php.ini file, not at runtime. The runtime configuration doesn't help you one bit when the error happens before that (e. g. due to syntax problems).
  13. I don't have any specific recommendations. Pick a project which is actively maintained by a group of developers (rather than code from a random website). This is a lot about personal preferences. Do you want your routes in a code or in an external configuration file? Do you want reverse routing, i. e. get URLs from routes? The native rewrite engine might be slightly faster than running PHP code, but this is just a small part of request processing. In any case, manually maintaining rewrite rules for a non-trivial site is a PITA. I remember one project which actually did that, and everybody regretted it. The only thing you should avoid is passing all requests to the router. Static files should be handled by the webserver itself. But since Slim appearently does that already, I don't see any problem.
  14. I think what you're actually talking about is a routing engine. That's the part of Slim which is responsible for processing pretty URLs. You don't need a completey framework if you just want a router, there are plenty of standalone libraries. Are there any reasons for using a router? You already answered that question yourself: Yes, they let you get rid of low-level URL manipulations. Your remark about performance issues(?) I don't understand. Routers aren't ideal compared to what? The Apache rewrite engine?
  15. The point is that an object property itself is just a dumb piece of data. It doesn't do anything. When you say that it “uniquely identifies an object”, that's just your human understanding of the context. PHP doesn't know anything about this. So if you want to perform any kind of lookup operations based on object properties, you or somebody else needs to implement a data structure which supports this. It can be as simple as a (nested) associative array or as complex as a full-blown ORM.
  16. By the way, it's generally best to not let users enter arbitrary digits in the first place. If there's any chance you can offer a proper datepicker or even just a dropdown menu, do it. It will save you a lot of trouble.
  17. checkdate()
  18. Then there's still another issue, maybe a syntax error, maybe something else. Turn your error reporting all the way up and make PHP display errors (this isn't your production server, right?). What does the script say now?
  19. Besides all that: Do not ever include passwords in a URL. Not only will the plaintext passwords appear in all kinds of logs and be sent to any external link via the referrer header. The mechanism can also be used for a log-in CSRF attack where the attacker creates a dummy account on your site and then makes the victim use that account rather than their own: https://www.yoursite.com/login?username=account_of_the_attacker&password=... If the victim clicks on this URL (which may be hidden behind a short URL), the victim will unknowingly be logged in under the attacker's account and leave all kind of sensitive data while browsing your site. So the URL is definitely the last place for a password. Instead, simply make the log-in form of your main domain post to the subdomain (via the action attribute).
  20. The PHP tag in the main script around the include statement is malformed: <php
  21. I have a hard time making sense of the question. You want to identify an object by multiple properties? In what context? Looking up an entity by a key implies that there's a collection of entities (like a relation in the relational model). What is your collection?
  22. Because your setDados...() function again splits the list of all escola IDs and makes an insert for every escola ID and every dominio ID. If you call the function three times (once of every escola ID), it performs 3 * 3 * [number of dominio IDs] insertions. Appearently you want to pass just one escola ID to the function, namely $id from the outer foreach loop. The function design in general is odd. If you want to pass multiple values, use an array, not those weird comma-separated lists.
  23. Why don't you simply order the rows by brand and category, iterate over them, store the last seen brand and categoriy in a variable and only display the brand/category when it is different from the last seen one? last_seen_brand := nil last_seen_category := nil for row in rows: show_brand := show_category := false if row.brand /= last_seen_brand: show_brand := show_category := true last_seen_brand := row.brand if row.category /= last_seen_category: show_category := true last_seen_category := row.category print_row( (if show_brand then row.brand else ''), (if show_category then row.category else ''), row.product )
  24. What is the problem you're trying to solve? You've spent a lot of time thinking about implementation details, but why do you want to merge multiple requests into one? Is this supposed to be some kind of optimization? If so, what are the underlying performance issues, and how exactly does your approach solve them? The very first example with four separate requests makes perfect sense to me. The “optimized” requests don't.
  25. This doesn't require any programming skills, just common sense. Right now, you have this: echo '<strong><h4>' . $startDate . '</h4></strong>'; the_title( '<h5>', '</h5>' ); That's an h4 elment with the data followed by an h5 element with the title (I have no idea what the strong element is doing there). If you want to put the title into the h4 element, do it: echo '<h4>'.$startDate.' : '.the_title('', '', false).'</h4>'; The third argument of the_title() tells Wordpress to return the title rather than print it.
×
×
  • 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.