Jump to content

requinix

Administrators
  • Posts

    15,274
  • Joined

  • Last visited

  • Days Won

    432

Community Answers

  1. requinix's post in running another client side program with in my HTML was marked as the answer   
    To the question you asked, kinda. To the question I think you're trying to ask, no.
     
    It is possible for a web server to run things like "programs". They run on the server itself. It is not possible for the server to cause a program to run on the client. That would be really, really bad.
     
    There are workarounds for very specific environments, like Windows domains when people are using Internet Explorer/Edge, not to mention completely unrelated mechanisms like a network-local server remotely running commands on the client machine itself, but that's something else.
  2. requinix's post in A Function Parameter That Takes In A Constant, Can It Always Take In A Variable Unless It Needs A Handle ? was marked as the answer   
    The only difference that matters here between a variable and a constant is that a variable can be modified and a constant cannot. If something does not need to modify a value then it doesn't matter which one you use.
  3. requinix's post in What Is An Element In Php ? was marked as the answer   
    That's right. 

    I was responding to the "3 could mean anything" comment. It does not mean anything. The manual specifically says the function tells you "the number of elements in array_or_countable". 

    I mean exactly what the words themselves mean. In code you could say
    count(array_keys($array)) == count(array_values($array))A bit of a recursive definition, admittedly.
  4. requinix's post in Relinquishing memory in WHILE loop was marked as the answer   
    In general you want a buffered query: it's much faster, frees up your connection for another query, and releases database resources. An unbuffered query is the opposite of that, but uses far less memory for large resultsets. 
    The second point in there is where the closed cursor comes in. Basically, a resultset needs to reach the end* so that both sides of the connection know the data is read and the server can do other stuff. IIRC closeCursor()-type functionality guarantees that the resultset was fully read and then immediately releases some client resources (which would have been freed normally eventually anyways).
    fetchAll() reads everything (either from memory or from the server) and gives you an array, so one way or another the resultset is fully used up. fetch() gives you just one row so you're still subject to un/buffered query rules.
     
    And yes, a distinction between buffered and unbuffered resultsets is common in client APIs for databases. (The server doesn't know or care either way.)
     
    * Past the end, actually. The client doesn't know it's at the end until it fails to read another row. The row count is actually maintained by the client as a counter from it reading rows - it's not sent by the server with the results.
  5. requinix's post in htaccess hotlink filter with remote "readfile" was marked as the answer   
    Whoever wrote those didn't quite understand what they were doing. You only need one for a domain.

    RewriteEngine on RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mydomainhere/ [NC] RewriteCond %{HTTP_REFERER} !^https?://(www\.)?otherdomain/ [NC] RewriteCond %{HTTP_REFERER} !^$ RewriteRule \.(gif|jpg|png)$ - [F]The third line is to allow direct access in the browser, ie. copying and pasting the URL into the address bar directly.
  6. requinix's post in Why Did Session Object Destruction Failed ? was marked as the answer   
    It happens when the session data could not be deleted. You're probably using regular session files, so that means the file couldn't be deleted: it may have been already (somehow), or maybe permissions were messed up, or perhaps the file was locked because PHP was still using it (I don't know about that one).
     
    Adding session_regenerate_id() will only cover up the problem by switching the session ID to something else just before you delete it. Extra work for no gain.
  7. requinix's post in Dealing with Triggers... was marked as the answer   
    Yeah, that's not even close to valid syntax. I linked the docs in the other thread.
     
    If your original query was

    update a_players p join wp_terms t set p.wpID = t.term_id where t.slug = p.wpSlugand NEW.term_id and NEW.slug are both things, then
    update a_players set wpID = NEW.term_id where wpSlug = NEW.slugSince wp_terms.term_id is an auto_increment-ed primary key you'll have to run this AFTER the insert so you can get its value. 
    If you describe it that simply, yes. What I'm saying is that if you describe it precisely, as we've both done a few times now, it no longer is what you want. The end result is correct but the process to get there is not.
  8. requinix's post in file system performance; how many files in one dir was marked as the answer   
    Depends on the filesystem. ext4 (most common?) doesn't have a limit per directory. However directories themselves take space to store a list of their contents, and unless the system sorts directory entries (?) looking for a file requires scanning the directory list for it.
     
    It might be antiquated now but if you know the filename from another source then I'd partition. I tend to generate hex filenames and take the first two bytes' worth as two subdirectories.

    /01/23/0123456789abcdef.extAssuming an even distribution, by the time you've filled each second-level directory with 256 files you've stored 16M total. More than enough.
  9. 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.
  10. 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.
  11. 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?
  12. 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.
  13. 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.
  14. 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).
  15. 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.
  16. 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.
  17. 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).
  18. requinix's post in summing using dynamic sql was marked as the answer   
    When it doubt, RTFM.

  19. 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.
  20. 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;
  21. 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.
  22. 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.
  23. 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.
  24. 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> ";
  25. 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.
×
×
  • 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.