-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
In PHP, how to save a password in encrypted form ?
requinix replied to abhik143's topic in PHP Coding Help
First, you want hashing. Encryption is when you can get the original password back from your database. That sounds good but it isn't. What you need is hashing, which is taking something like a password and turning it into another thing that looks random but will give you the same result for the same password. (Basically.) Then you compare hashes. Use password_hash and password_verify like // when setting or changing a password $hash = password_hash($_POST["password"]); /* put $hash in the database */ // when checking a password if (password_verify($_POST["password"], $hash_from_database)) { // password matches } else { // password does not match } -
HTML or PHP - which is better for search engines
requinix replied to Walled's topic in Miscellaneous
I assumed the question was about extensions - .html and .php. But any way I interpret the question, the answer is the same. -
HTML or PHP - which is better for search engines
requinix replied to Walled's topic in Miscellaneous
They don't care. -
The question marks are supposed to be there. That's how prepared statements work. Wikipedia
-
What is the new error message?
-
You're binding just fine. SQLSTATE[23000]: Integrity constraint violation: 19 users.active may not be NULLSince active isn't in your list of columns to insert, the database will use the default value. But the default is (apparently) null. The result is that you have to specify the active value when adding a new user.
-
It matches both because you aren't using anchors to enforce a match against the entire string. All you're doing now is checking if the string contains those patterns.
-
Use usort() with strnatcmp() to implement your own sorting algorithm. usort($FIRST_NAT_SORT, function($a, $b) { $a1 = strtok($a, "-"); $a2 = strtok(""); $b1 = strtok($b, "-"); $b2 = strtok(""); return strnatcmp($a1, $b1) ?: -strnatcmp($a2, $b2); });[edit] It's been asked so I'll explain: The function to usort() has to return 0 depending on how the two arguments ($a and $b) compare to each other - negative if $a $b. Fortunately that's exactly how strnatcmp() behaves too. return strnatcmp($a1, $b1) will handle sorting for just the parts before the hyphens, but if they're equal then you need to compare the parts after the hyphens. $x ?: $y is shorthand for $x ? $x : $y, so return strnatcmp($a1, $b1) ? strnatcmp($a1, $b1) : -strnatcmp($a2, $b2);(except the shorthand will only evaluate the first strnatcmp() once) Since strnatcmp() returns 0 if the two are equal and nonzero if not, the function will return that number if the two are not equal because it won't try to do the second comparison. If they are equal then the second strnatcmp() does get evaluated. It works the exact same way as the first one, except it has a minus sign to negate the return value. Thus the result is backwards: negative if $a2 > $b2 and positive if $a2 $b2. The effect is a descending sort on the values after the hyphens. To be absolutely explicit about everything you could write that line as $compare1 = strnatcmp($a1, $b1); if ($compare1 < 0) { // $a1 < $b1 return -1; } else if ($compare1 > 0) { // $a1 > $b1 return 1; } // $compare1 == 0 and $a1 == $b1 $compare2 = strnatcmp($a2, $b2); if ($compare2 < 0) { // $a2 < $b2 return 1; // opposite result } else if ($compare2 > 0) { // $a2 > $b2 return -1; // opposite result } else { return 0; }
-
Clearly OP doesn't have the understanding or the inclination to let us help him.
-
Storing file modification date in database
requinix replied to NotionCommotion's topic in PHP Coding Help
To me it depends on what the date represents. If it's an actual piece of relevant data then you should put it in the database, but if it's just an artifact of the file itself then leave it with the file. So probably the former. -
If it's your own content then that deals with the more problematic restrictions, but you still can't scrape their site to get what you need. The API does provide a way, but it requires generating access tokens by logging into their site; there's no indication how long those tokens are good for (just an ominous warning that they might expire in the future) so you will probably have to re-login to keep the feed working indefinitely. So here's what I propose: You take the officially-supported API route. Make an application according to their guidelines, and to alleviate most of the burden of the API you can use a third-party library to do the communication parts, then use their /users/self/media/recent endpoint to get the images. Yes, it will take you a little longer, yes, it's not as simple as scraping, but that's the method they require so that's what you'll need to do.
-
Okay, see, now we've got a bit of a problem: Instagram doesn't like people doing what you're doing. Their Terms of Service specifically disallows crawling media (General Condition #9), their API policy says you can't "simply display User Content" without permission (General Terms #16), and the less precise "Platform Policy" list in their documentation says you can't crawl media without users' consent or automate requests (#4, #5). And on a more technical note, their API doesn't provide a way for you to access user media without them specifically logging into Instagram. As far as I can tell. I'm not sure there are any alternatives open to you...
-
I haven't seen anything to suggest this sort of behavior is not allowed... What's your code? If it handles those URLs at some point between the RSS and Telegram then you can simply remove the query string before submitting them.
-
Why remove it? What's the problem?
-
check value stays unchanged even after form submit?
requinix replied to lovephp's topic in Javascript Help
Okay, great, so now we've established that the code you're posting is not the actual code you have. The first step is to post your actual code. Also, if you need to know three states for the input (default, checked, unchecked) then a mere checkbox is not enough because all it can tell you is whether it was checked. You'll have to combine that with knowledge about whether the form was submitted. -
Validating HTML and counting elements
requinix replied to NotionCommotion's topic in PHP Coding Help
To validate the HTML... well, you know HTML is rather flexible. "string" is valid. " string" is valid". Some stuff you might consider invalid is still acceptable to browsers. I'm thinking (a) just load it with anything in PHP that supports HTML and see if it complains, or (b) try Tidy. Maybe your end result should be less valid/invalid but whether it's supposed to be valid already and you can just fix it if it has minor errors? -
check value stays unchanged even after form submit?
requinix replied to lovephp's topic in Javascript Help
I don't get why you expect it to show anything other than 5. It's what you put into the HTML. Directly. No PHP code, no variables, no Javascript to update the value on page load... Why do you think it should be anything other than "5"? -
Notification emails would have been broken too. Are they working now? Actually, I can see some emails to you being sent. A couple bounces. You should be receiving a lot of them about now...
-
Rpc technology to enable remote access to my application db.
requinix replied to glph's topic in PHP Coding Help
Direct access to the database is a really bad idea. Really bad idea. Why can't you modify the application, in order to implement an API? That is the best option. -
Once again, validation and notification emails broke on the server. They should be fixed now. I don't remember what the earlier issue was but I think this one is different. It's going through the backlog of verification emails so anybody missing theirs will probably get them within the next day or so. If you still haven't received yours by then, or want it now, then use the Resend link at the top-right of the page. (If you don't have a link then you don't need to validate.)
-
How can I rewrite .JPG to .jpg on any incoming urls
requinix replied to shadiadiph's topic in Apache HTTP Server
Apache's mod_speling has something to "fix" case-sensitivity problems. In your case it should respond with a redirect to the properly-cased filename. CheckCaseOnly onCheck your server access logs periodically over the next few months. When you see that the number of requests to the uppercase filenames has dropped to nearly zero then you should remove the directive and let nature take its course with the remaining stragglers. -
There are too many things that are optional in that regex. Either you need to make some stuff required or you should combine some of them with alternation and make the whole set required. (first?)(second?)(third?) -> (?:first|second|third)If neither of those then we might have to rebuild the regex from scratch...
-
I can't tell what you're asking for. Do you have an example of the input string, current output, and desired output? "or one". Not many. * is none or many.