Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Large switches can be inefficient, because they are effectively the same as if/elseif/elseif/elseif/else. So I would expect that at a certain switch size, variable functions would become more efficient. Only benchmarking will say for sure though.
  2. I don't think I understand what you are trying to do. You can use fwrite() to write any string directly to a file, including strings containing what I would call "binary data". Do you want to encode the string somehow before writing it? If so, what encoding do you want to use?
  3. A good start would be to add error checking for every single operation which could fail. That includes the api fetch and each database query.
  4. I would have gone for fwrite($handle, $string); and cut out the middle man.
  5. I didn't reply earlier because I'm not sure what kind of salt you are using. How are you using the salt?
  6. It's probably easier if you read the file line by line, with a loop like this: while ($line = fgets($fh)) { if (strpos($line, '>>') === 0) { # This is a matching line } }
  7. I've never used them myself. I can see how they could be useful in large applications where some libraries might have conflicting class names or similar issues. I imagine it would be useful to allow code from two monolithic applications to be integrated without a lot of renaming. Perhaps both apps have a "Db" class with a different interface.
  8. There's two parts to that. Start with reading the file and outputting it exactly as it is. Then add a filter that outputs only lines with >> at the front. If you have a go at it then we can help when you get stuck.
  9. It means "If you don't know what a namespaced class is, it doesn't affect you" Here's what the manual says: http://php.net/manual/en/language.namespaces.rationale.php
  10. It can be a lot of things. The data connection ports might not be open, you might need to switch on/off passive mode, or the client may have ftp blocked altogether. It's difficult to guess what the problem is. Can you show your code? Then we can at least check that it's being called correctly.
  11. You could store the total in the session as well, and update it only when the cart contents and/or their prices/quantities change. That's more efficient than calculating it every time.
  12. The line number (which seems to be missing) should be a clue that it's not the loop itself, it's this: echo "value is $value3['cli']"; Change that to: echo "value is {$value3['cli']}";
  13. That's the old convention in PHP. The new magic constructor name is __construct(). I can't help with Java, as you said, this is a PHP board
  14. It's not as simple as that.. there are languages, there are characters, and there are character encodings. Languages are written in characters, but you can't store a character into a database directly, it has to be in some kind of encoding. Usually databases will be using Latin 1, ISO-8859-1 or UTF8 as the default encoding. But as long as you are consistent with encodings, then yes, you can just take the data from the textbox, insert it into the table (using mysql_escape_string()) and then fetch it back again. The simplest way is cheating a bit, but if you leave your database encoding as a basic one like ISO-8859-1 (likely to be the default), then you can insert ANY encoding into it and fetch it back without problems. On the other hand, if your database is UTF8 then it will reject anything that's not UTF8, and you might find other, more common japanese encoding like SJIS or EUC-JP get rejected, unless you first convert them to UTF8. So the simple way - database encoding as ISO-8859-1 or Latin 1, insert your data with escaping, fetch it back and put it back into your HTML. Ideally your HTML and/or your content headers should indicate what encoding you're using as well.
  15. Your query failed because the sql is invalid, so $query2 is the boolean value "false". A simple way to check for errors is like this: $query2 = mysql_query($sql2) or die("Query failed: $sql2\n": mysql_error()); To fix the query, try removing the [ and ] characters.
  16. if ($value->showlogin = 1) { should be if ($value->showlogin == 1) { Even experienced programmers get that wrong every now and then Some programming languages will give you a warning if they see that kind of mistake.
  17. Oh I just remembered my other complaint - php does not have lexical or file scoped setting of warnings, and some of the warnings it gives are just plain annoying. I don't want to have to check if an array index exists before accessing it - I should be able to easily switch this off while maintaining other warnings which are actually useful, particularly reading from a variable which hasn't been set to any value. Perl does this much better.
  18. There's a wealth of complaints by me about php memory usage here: http://btherl.livejournal.com/?tag=programming Along with some other php and postgres complaints. With postgres it's mainly the braindead query plans it comes up with sometimes, and the total lack of ability to override them. Still on the topic of memory usage, it would be nice if php had a native array type which acted like a C or Perl array, and didn't store all the indexes as zvals. It's such a waste.
  19. Maybe try passing the timezone in the constructor for DateTime()?
  20. Inheriting bad code from someone else and having to maintain it Not really a php specific gripe I suppose.. My biggest php complaint would be its extortionate memory usage. This topic should probably go in general discussion, I'll report it and see where the mods move it..
  21. Your outermost while loop is missing the opening and closing braces, the "{" and "}". As a result, only the "if ul > 3" is within the while loop, and the "if view == 2" is not.
  22. Ok I get it now. No, there is no chance, because you have removed all characters except letters and numbers already. That means that "../" has been removed by the regexp already. The regxp is all you need to be secure. You can add underscore to the regexp safely if needed.
  23. From your post where it was always returning true: if(preg_match("[a-z]",$str)) { That should be if(preg_match("/[a-z]/",$str)) { I find the best way to remove unwanted characters is to list the ones you DO want, and invert that. For example: $filtered_str = preg_replace('/[^a-zA-Z]/', '', $str); That will remove anything which is NOT in the ranges a-z or A-Z.
  24. Once you've removed all characters which are not alphanumeric, it's not possible for there to be any dot, slash or percent symbols left in $pageNewID. So the strstr() tests are redundant. I'm not sure if that regexp is doing what you want it to though. For example, it'll do these conversions ../../../etc/passwd => etcpasswd files/file_5.txt => filesfile5txt It'll remove file extensions as well as any legitimate directory names. I think you need to allow dot and slash in the regexp, and keep the strstr tests. Is this running on unix or windows?
×
×
  • 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.