-
Posts
15,227 -
Joined
-
Last visited
-
Days Won
427
Community Answers
-
requinix's post in Question On The Variable (Array Value) was marked as the answer
It holds each value from the $colors array, one at a time. -
requinix's post in Scary Warning? was marked as the answer
PHP Freaks is now brought to you by common sense and the letter A.
-
requinix's post in Execute shell script in PHP was marked as the answer
0777 on the script means anyone can read, write, or execute the script.
If you're absolutely sure that the script is safe to execute - no vulnerabilities - then you can setuid it to cause it to be run in its owner's account instead of Apache. But there's no guarantee the system will honor that.
Otherwise it would be great if you could change things so that the directory it needs to write to is also owned by Apache. Means your personal account couldn't change anything inside without sudo but the script could run without fiddling with permissions.
Worst case, set 0777 on the directory so that anyone can read the directory, write new files in it, or traverse the directory.
It says what? -
requinix's post in PHP startup warning on amazon aws was marked as the answer
Check the PHP configuration used with Apache. You at least display_errors=off, so set error_log to somewhere appropriate, restart Apache, and try again.
But the problem is probably a missing mbstring.
Depends on the configuration. It could. Personally I wouldn't use a separate configuration for the two.
You have php-fpm installed, which works differently from a regular Apache module. Now you need to look at its configuration to see what it has. The logs would probably be in /var/log/php-fpm. -
requinix's post in PHP get cURL response value as variable was marked as the answer
No, that's not the problem.
I skipped the first half of your post and went straight to the second part, where you said you had some JSON and couldn't get the success value. I didn't notice that you don't actually have the JSON.
cURL will output stuff by default. That is what your code is doing now: outputting the JSON to the browser. That's how you're able to see what it is. Instead, you need to get that output into a variable. You do it with the CURLOPT_RETURNTRANSFER option.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);When that is set, the return value from curl_exec (which you have as $ch_result) will be the response as a string. The JSON.
You then need to decode that variable. Not $ch, which is just a cURL identifier for doing cURL operations, and useless once you've curl_close()d it. Which, by the way, you need to do if you aren't doing it already.
$json = json_decode($ch_result);And now you can properly use var_dump to see the value you want:
var_dump($json->success);It will say either bool(true) or bool(false) - anything else probably means there's still an error in your code.
If you think something should be true/false and you get null then don't just roll with it. Find out why it's doing that and not doing what you expect.
-
requinix's post in Upgrading Php4 to 5 & mysql to mysqli - Warning: mysqli_query() expects parameter 1 to be mysqli, null given was marked as the answer
If you're upgrading then you might as well go for PHP 7: 5.6 is the last of the 5.x series (there is no 6.x) and is no longer receiving feature updates. 7.0 is out, 7.1 is out, and 7.2 is coming out fairly soon. The good news is that 5->7 has fewer big changes than 4->5.
Anyway, variables defined outside of a function are not available inside of a function. Files themselves don't have scopes (they kinda do but nothing relevant here) so that's not it.
Not that you've actually said what your problem is - just a vague "it doesn't work".
If you want a quick way to get a mysqli object (which is what $mysqli actually is) then you can do
function db() { static $link = null; if (!$link) { $link = new mysqli('localhost', 'username', 'password'); $link->select_db('database') or die ('Cannot connect to database'); } return $link; }and
function body(){ $sql = db()->query("SELECT * FROM articles ORDER BY article_number DESC LIMIT 11, 15");1a. Notice that it's the OOP style. PHP 4's object-oriented support was... lacking. In PHP 5+ it's much better. You could stay procedural with the mysqli_* functions but try to learn OOP.1b. If you really don't want to do it then use db() in place of the $link in the regular function calls.
2. The "or die()" pattern is very bad. Stop doing it and figure out something better.
3. Putting database error messages in the die() is even worse.
Likewise,
while($row = mysqli_fetch_array($sql)){1c. $sql is also an object and you can do $sql->fetch_array() instead.
Also,
stripslashes(extract($row));5. That doesn't work, least of all not the way you think it does.6. stripslashes() like that is not even needed in PHP 5+.
7. extract()ing values is frowned upon for assorted reasons. Assign variables manually (yes, it's more code) or simply just reference the values in the $row array directly (easier).
-
requinix's post in Can't Report on Mobile was marked as the answer
How about now?
The reporting page isn't terribly pretty on mobile but at least it's accessible. And functional, I hope.
-
requinix's post in is it possible to set permissions on a folder outside the root using yml was marked as the answer
Please remember to give context for people who don't know you're working with CodeDeploy.
It doesn't look like their permissions system is particularly powerful - since "directory" only applies to descendant directories and "file" only applies to immediate files, you would need a bunch of sections listing out each individual directory whose files you wanted to change permissions on.
Try deploying with a .tar/.tar.gz (and not a .zip) as those support specifying permissions inside the archive itself. No guarantee that CodeDeploy will keep the permissions on extraction, though.
Otherwise I think I would give up and use a post-install bash script (or individual commands without the script) to apply permissions as you want. Probably with a combination of find+xargs+chown/chmod.
-
requinix's post in Rearranging Our Forums was marked as the answer
Just updated the forums.
If anyone has comments or suggestions about the changes, head over to the Feedback forum (which is now situated in the "General Discussion" category).
-
requinix's post in Subtracting Time from Total Hours was marked as the answer
Apparently createFromDateString doesn't allow HH:MM format, even though it looks relative. It's because the relative format is shared with the other date/time parsing code and HH:MM is more of an absolute value than a relative one.
So break the HH:MM into HH and MM parts and create the DateInterval manually. You do need to validate the break1 value first (make sure it is, in fact, HH:MM format) but the rest of the process we described works correctly.
-
requinix's post in Script posting wrong date was marked as the answer
The $b++ at the top of the loop is still going to happen. And putting $cycle_day++ into that doesn't make any sense at all - yeah, it increments twice to make up for the missing $b day, but that doesn't justify it being there.
The code is already plenty messy and long past the point of needing to be refactored, but fixing this should be close. If the first week works then $b=0..6 and $s=-1..5 works. So keep it in that range.
Drop the $b
Then deal with the $b++ problem. Resetting $b anywhere after it's used (which is just with the $s=$b-1 statement) won't be enough because it'll increment with the next loop. Drop the increment and
$s = $b - 1; $b = ($b + 1) % 7; -
requinix's post in Undefined constant, but it is defined was marked as the answer
Either the error message is pointing to a different line than the one you showed or __autoload is running before ROOT was defined.
But put that aside for a second and stop using __autoload.
-
requinix's post in experts please take a look seo url issue was marked as the answer
It's not too tough. As I see it, the main problem is that you know just enough to venture out and try doing everything, but you don't know what you actually need to know.
1. If you want actual category names then use .* instead of \d+
2. If you want /category to show, presumably, all categories, then fix your cat.php so that if "cat" is empty then it shows all categories instead of redirecting.
-
requinix's post in how to set a functions/scripts folder outside the root in aws codedeploy was marked as the answer
You have a files: section in there, right? That's how it copies files. If you want to copy outside the web root then just make it do that.
-
requinix's post in PHP pagination with sessions was marked as the answer
Eh, I should stop being lazy.
Create an array to track the variables you want to pass between pages. That's the from_date and to_date.
$qs = array( "from_date" => $_GET["from_date"], "to_date" => $_GET["to_date"] );When you want a link, use /pagingstatic.php with http_build_query($qs). When you want a page number too, use array_merge with $qs and the page number.
$prev = ($page - 1); $link = "/pagingstatic.php?" . http_build_query(array_merge($qs, array("page" => $prev))); echo "<a href=\"".htmlspecialchars($link)."\"><<Предишна</a> "; -
requinix's post in stuck at a point in aws codedeploy and bitbucket integration was marked as the answer
It's quite a bit harder to figure this out without being in the AWS console...
Yeah, now that I look more into it, that's not the right one to link to.
CodeDeploy supports S3 and GitHub natively and can use them as places to get source files from. It does not support Bitbucket directly.
Instead, Bitbucket is the one that supports CodeDeploy. It will push source files into S3 (using the bucket you tell it to use), then it tells CodeDeploy to perform a deployment (deploying the group you tell it to deploy). That deployment itself is configured to use S3, one way or another.
So the best set of instructions will be the ones that tell you how to set up a deployment with S3. But that still comes in two flavors: deploying to an existing instance, or deploying to a new instance.
I think you're trying to work with an existing instance? That means these instructions.
For the IAM I think you need the first link I posted. Check that the one you made followed all the instructions? And supposedly you can change IAM roles after creating the instance, so maybe just create one and try adding the role after it's running.
-
requinix's post in Difference between PC development environment and hosting. was marked as the answer
Ha. Ha ha. Hahahaha.
Yes. And that only scratches the surface of how files work differently between the two.
Always use forward slashes / for file paths. They work on Linux and Windows. Backslashes \ work on Windows but not on Linux. Backslashes are also special in PHP strings, and accidentally writing "path\to\folder" won't even work on Windows (though 'path\to\folder' will).
A leading slash has special meaning, too. Like how \misc on Windows means C:\misc (or whatever drive), /misc on Linux means the root of the filesystem. When locating files on your site, use the DOCUMENT_ROOT as a prefix. It's the path to the public root of your website.
include($_SERVER['DOCUMENT_ROOT'] . '/misc/mem_header.php');On Windows you'll sometimes see filenames with \ and / mixed. As long as the backslashes are coming from PHP itself (like the DOCUMENT_ROOT) and not your own code that's okay and you don't need to worry about trying to fix it. -
requinix's post in Keeping URL Elements after form submission was marked as the answer
Make the form submit to the URL you want, and/or make the code redirect to the URL you want.
Really that simple.
-
requinix's post in creating table from array with different value was marked as the answer
This goes so much more easily when you preprocess the data into associative arrays.
$graph is the unserialized array you posted* but without the [age] you added to it.
<?php foreach ($graph as $grade => $data) { $monitors = $days = []; // preprocess foreach ($data as $data2) { $monitors[$data2["label"]] = []; foreach ($data2["data"] as $data3) { $days[] = $data3["x"]; $monitors[$data2["label"]][$data3["x"]] = $data3["y"]; } } // clean $days = array_unique($days); sort($days, SORT_NUMERIC); // draw table ?> <strong><?=strtoupper($grade)?></strong><br> <table border="1"> <thead> <tr> <th>Monitor Label</th> <?php foreach ($days as $d) { ?> <th><?=$d?>D</th> <?php } ?> </tr> </thead> <tbody> <?php foreach ($monitors as $label => $mdata) { ?> <tr> <td><?=$label?></td> <?php foreach ($days as $d) { ?> <td><?=$mdata[$d] ?? ""?></td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php } <strong>25P</strong><br> <table border="1"> <thead> <tr> <th>Monitor Label</th> <th>1D</th> <th>2D</th> <th>3D</th> <th>6D</th> <th>7D</th> <th>15D</th> <th>28D</th> </tr> </thead> <tbody> <tr> <td>C81</td> <td>6.220000</td> <td>10.220000</td> <td></td> <td></td> <td>21.440000</td> <td></td> <td>30.780000</td> </tr> <tr> <td>C82</td> <td>8.000000</td> <td></td> <td>20.890000</td> <td>30.670000</td> <td>32.555000</td> <td></td> <td>51.110000</td> </tr> <tr> <td>C83</td> <td>7.110000</td> <td></td> <td>19.780000</td> <td>23.560000</td> <td>32.225000</td> <td>38.890000</td> <td></td> </tr> </tbody> </table>* Please don't post serialized data. It's impossible for humans to read. Post the print_r or var_dump output. -
requinix's post in delete account was marked as the answer
Our policy is not to delete accounts or content. If you don't want to be an active member anymore then simply don't be an active member anymore.
-
requinix's post in how to display in html table was marked as the answer
If all you want to change is to have those items listed in order then notice that GROUP_CONCAT can sort too.
-
requinix's post in add a update statment MS SQL in php was marked as the answer
Forget about $orderid.
The data is coming from the $sql2 query, right? Every single $orderid came from that query, right? That query is what decided which orderids to return, right? It looked at everything and decided which ones to get, right?
Now you want to do something to all those orders that came back, right? They all get the same treatment, right?
Look at the query you started with. You gave it conditions to match against each order.
Here's where it gets magical:
If you do an UPDATE query with those very same conditions then it'll target the very same orders that the first query returned.
You follow that? So. All you have to do is make a new UPDATE query with the right syntax that does the thing you want it to do, copy those conditions from the earlier SELECT, and run it.
-
requinix's post in delete from table where NOT IN array was marked as the answer
Also works, but with a small problem: the player names are strings, so not only do they need quotes
$query = "DELETE FROM `garage_list` WHERE `player` NOT IN ('" . implode("','", $cart) . "')";but the names would have to be escaped - or use a prepared statement instead. I went with the account_ids instead since they're numbers which makes it a bit easier, but looking at it now it's not actually that much less work. -
requinix's post in Storing credit card details... was marked as the answer
Do you? I mean is there a real reason why you can't penalize a non-paying user for skipping out? Is there some reason why a finished auction cannot be restarted due to lack of payment? You could always, say, have the second-highest bidder inherit the winnings if the highest doesn't pay up.
Anyway, you do have some leverage, whether you like it or not: the technical and business requirements of your application. Whatever gateway must have a way of performing the actions you need - the clients can choose whichever service they want but it must somehow support certain features.
Storing details is out of the question. Don't do it. It's a huge hassle, not to mention a big responsibility with legal ramifications for failure.
The problem you're trying to solve is that you can auth for an amount but if the bids get too high then you're stuck. I can think of a couple possible business-rule solutions to that:
1. Auth for the initial amount, possibly a bit more, and have the user re-auth if the bidding goes over the limit imposed by the gateway. Or a fixed amount. Whatever.
2. Implement auto-bidding: user puts down the highest amount they're willing to bid and you auth for that much. Then auto-bidding rules kick in. If the user loses out then they can re-auth for a higher amount.
3. Act as a sort of gateway yourself. Use whatever actual payment gateway(s) you want, you take all the money directly, then you automatically/periodically transfer funds to the clients. You have full control over everything.