|
Golbez posted:
If I remember right, "echo" is very very very very very very very slightly faster than "print" -- trivial. There's also some other bullshit that this StackOverflow question explains. However, in general, for basic poo poo like echo "Some poo poo here."; use whatever works best. I did a lot of stuff in QBASIC when I was younger and "print" got stuck into my brain, so it's what I end up using more often when I'm not mixing them up. Short version: The only difference you're really likely to run into as a sane developer is that you can do "... or print('yyy')", but not "... or echo('yyy')".
|
# ¿ Oct 6, 2012 23:14 |
|
|
# ¿ May 7, 2024 09:02 |
|
Fleur Bleu posted:I was browsing the mysqli function list, wondered what kill did, skimmed it's article, saw "kill process" and I thought "Thats sounds good, let's put that in.". Looking at it again, the examples use it the same way I do. The big problem I can imagine is if you're doing something big that the script isn't blocking over (e.g., running "UPDATE bigasstable SET x = y") you can kill the thread halfway into doing something. I only kill threads when something's gone completely off the rails and is locking tables and causing huge traffic jams. My boss did the same thing with mysql_free_result() and just started copy-pasting it after every mysql_query() (even ones that mysql_free_result() makes no sense for, like INSERT or UPDATE). Please don't be my boss.
|
# ¿ Oct 24, 2012 02:32 |
|
It's also good to remember that it's not how many queries, but what type and on what data. I've written queries before that took upwards of 5 seconds to run (and were difficult as hell to debug the issue with). You'll know when it's time to optimize.
|
# ¿ Oct 30, 2012 20:38 |
|
bobthecheese posted:The way my bank handles it, for example, is that it generates single-use keys for all actions. So, I assume, they store the "next action" key on the user's session, and attach the key into every link and form possible. If the passed key doesn't match the one in the session, then they reject the request and log the user out. On every successful request, they generate a new "next action" key. You can get around this by only checking the "next request" key on actions that would reliably need it. Alternatively, store a different key, that would expire after some amount of time (10 minutes?), and if that expires, then log them out. Breaking the open-in-new-tab and such features is a terrible design flaw.
|
# ¿ Nov 1, 2012 22:07 |
|
DaTroof posted:Close. If they have the same name, the value in $_GET/$_POST will simply be the last one received; but if you bracket the end of it (e.g., <input type="text" name="website[]" />), all the values will be appended to an array. You can also do fun things like this: code:
IT Guy posted:Everything that he said ^ We have an instance which I thought was part of the 0.1%; we store a CSV-list of numbers for a set that we use when adding a new object to the database. e.g. "object_defn [ id=1, something="such and such", subobject_ids="1,2,3,4,17,18,19,20" ]". When the code creates a new object, it pulls out the list of subobjects to make (and each one of those is a new row, so the CSV is only for the definition). After some thought, though, even that could probably be handled better, since a lot of object definitions have the same subobject_ids and we could skip the explode-insert loop in code using INSERT INTO ... SELECT. (The original designers used a lot of this CSV-in-a-database stuff for things that really should have been normalized, and we've fixed all but this one.)
|
# ¿ Jan 25, 2013 18:38 |
|
ATM Machine posted:I think it sounds like something is happening server side to alter the page by trying to insert something after a request for a PHP file is made, whatever its trying to insert has been removed or prevented, but whatever is doing it hasn't, so its adding in a blank newline. Wordpress was mentioned; I'm starting to wonder if it's possibly a rogue file somewhere that's doing it. Maybe it's something like auto-prepend-file in a php.ini or .htaccess somewhere. Try creating a page with just <?php phpinfo(); and see if it gives you any information. If that doesn't, try this: php:<? ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting (E_ALL); header("Content-type: text/plain"); print "Test"; ?> This is all voodoo debugging, though. Good luck finding the cause.
|
# ¿ Mar 6, 2013 00:29 |
|
Be sure that you're using htmlspecialchars() when outputting because <str: might make a web browser try to interpret it as HTML. If that doesn't help, does var_dump($_POST) show anything? What if you add other inputs to the form? Have you checked your browser request and made sure it's going through?
|
# ¿ Apr 17, 2013 04:31 |
|
duck monster posted:Chances are if I'm the only one working on it, my language choice wont even support private variables, because there isn't a reason ever not to use python duck monster posted:magic_variables_gpc (Also, double slashes should theoretically still be fine, as you'd end up going from \' to \\\' (the slashes get escaped too), which is the cause of badly designed websites that output \' instead of ') duck monster posted:There is THIS clanger however Something like "email=pwned@;funexploit" might work (it depends on if you can get away with using spaces)... the fact that it's blindly executing shell parameters without any sort of escaping is an absolute horror, though. It depends on where $email is coming from. If it's being escaped by PHP's shell arg escape function you might not have much luck.
|
# ¿ May 2, 2013 19:12 |
|
php:<?php function fart($array) { $c = 0; foreach ($array as $node) { if (isarray($node)) { $c += fart($node); } else { $c++; } } return $c; } Zamujasa fucked around with this message at 02:25 on Jul 20, 2018 |
# ¿ Jul 20, 2018 02:15 |
|
Agrikk posted:Can someone help me with a check to see if a row is complete? I'm assuming you're using some combination of explode to break out the values; in that case you could just... check if they're broken before processing: php:<?php $data = "a\tb\tc\n\tb\tc\na\tb\na\tb\tc\n"; $a = explode("\n", $data); foreach ($a as $l) { $la = explode("\t", $a); if (count($la) < 3 || $la[0] == "" || $la[1] == "" || $la[2] == "") { // do something else with this line, which sucks and is broken continue; } // do what you do for normal lines } Tei posted:After a second through. Is better to pass the id instead of the object, so the caller don't need to know about things he can live withouth knowing. Given a choice between "public function doThingWithBar(\Bar $bar)" and "public function doThingWithBarId($id)" I'd say you should prefer the former in all cases if only because it guards against something that isn't a Bar id getting in there. There's other value, but that's the easiest one to explain.
|
# ¿ Jun 6, 2020 18:49 |
|
rt4 posted:Use any VPS you like. Check AwfulMart for some decent hosts with goon discounts. Also this is way, way late, but as someone who has written several long-running processes (some that have been running for multiple months and in one case literal years): php isn't really any worse than anything else for running long-running processes, it's just that the way you build a long-running task is a lot different than the way you write normal ones.
|
# ¿ Jun 6, 2020 18:52 |
|
Biowarfare posted:I have quite a few PHP "workers" (that read off redis queues), and I don't see it being much different than node. You just have some kind of forked off child or blocking loop most of the time, instead of a top-down render resulting in stdout (to a page) I have a few that poll a database (someone else's bad decision) every second and write to some network ports, as well as another set that acts as a server/translator for some networked devices. Reads input, translates it into usable data, then pushes it out to other endpoints. Both of these tend to run for months if left undisturbed, and the only reason they don't last longer is because "make them recover from network errors" has never been in the time budget I like php just because it's easy to get started with and there's no gigantic pile of dependencies or requirements just to begin. Most of it is either just built in or in one of the typically-bundled extensions. You don't need to import 20 modules just to get printf. (I say this, then I was reviewing a new hire's 'code challenge' which involved 200 MB of php and node modules for what took about 30 lines of raw PHP )
|
# ¿ Jun 10, 2020 21:59 |
|
Good Sphere posted:
I'm going to ignore the rest of the posts in this thread just to point out my_script.php?MP4Address=../../../../sensitive_file_you_really_dont_want_sent. If this is what the original actually looked like, and you are not currently responsible for it: this is a trash fire, do not touch it and walk away.
|
# ¿ Apr 24, 2022 01:46 |
|
you can also pare it back a bit and test if it works at all. for example, what do you get if you run var_dump(shell_exec("echo test")); ?
|
# ¿ Jul 16, 2022 01:36 |
|
i just had to change $_GET['n'] ?? "default" to an isset($_GET['n']) ? $_GET['n'] : "default", so i feel you there
|
# ¿ Nov 3, 2022 18:52 |
|
Agrikk posted:What is the best way to accomplish this programmatically? it can be: php:<? function fart($roll, $wealth) { $rolls = [ 20 => [0, 0, 0, 0, 0], 40 => [0, 0, 0, 1, 1], 55 => [0, 0, 1, 2, 2], 70 => [0, 1, 1, 2, 3], 80 => [0, 1, 2, 2, 4], 90 => [1, 1, 2, 3, 5], 94 => [1, 2, 3, 3, 6], 97 => [2, 3, 4, 4, 7], 99 => [3, 4, 5, 6, 8], 100 => [4, 5, 6, 8, 10], ]; foreach ($rolls as $max => $table) { if ($roll <= $max) { return $table[$wealth]; } } } ?> it basically asks: "is the roll lower than 20? well, what about 40? what about 60?" etc. until it gets an answer, and then it returns the wealth level of that particular entry. the expected inputs are 1-100 for the roll and 0-4 for the wealth level, but you can make them anything. fart( 1 ~ 100, 0 ~ 4 ) edit: this is basically an implementation of the above poster's thought, but without the "minimum" range, since the minimums are always either infinity or the previous level's maximum. edit 2: i would argue one benefit of the above (with the proper formatting) is that it preserves a very clear 1:1 relationship with the original chart. if you saw the chart and the code side by side it's immediately obvious what the data is and how it should work (though of course if you're using it somewhere serious please add a few comments) Zamujasa fucked around with this message at 22:53 on Dec 29, 2023 |
# ¿ Dec 29, 2023 22:50 |
|
|
# ¿ May 7, 2024 09:02 |
|
it's like code golf but you're trying to hit the ball through windows
|
# ¿ Jan 3, 2024 01:50 |