Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. Why not just use time instead of $_row['current_date']? Have you checked that it contains a UNIX timestamp? By the way, 30 seconds doesn't seem like much for an online/offline indicator. Sure you don't mean 30*60?
  2. Not quite enough for CC info, I'm afraid: https://www.pcisecuritystandards.org/security_standards/download.html?id=pci_dss_v1-2.pdf The lawyers from Visa, MasterCard, AmEx, et al. are going to rape you if you don't follow those specs.
  3. if (strtotime($time)-60 > time()) { echo 'within the last minute'; }
  4. Haha... http://farm4.static.flickr.com/3604/3585051300_d23a37a32e_o.png
  5. Things like $password = sha1(mysql_real_escape_string(htmlspecialchars(trim(strip_tags($_POST['password']))))); are also completely redundant. sha1 will always return a hexadecimal number, and there is no input to sha1() that is unsafe. No they're not. Check the manual for the differences.
  6. http://img3.imageshack.us/img3/4821/bingsuckscommicrosoft.jpg
  7. I've been wondering that as well. Just seems like a relaunch to me. live.com is also redirected to bing.com.
  8. What kind of encryption are you talking about? Have you actually tried using the encryption algorithm you had in mind?
  9. It's documented in the manual: On this very cool place called the manual there are also some nice people who have researched stuff for you, and you would find out that you can get the size like this: function getSize($file) { $size = filesize($file); if ($size < 0) { if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { return trim(exec('stat -c%s ' . escapeshellarg($file))); } else { return exec('FOR %A IN (' . escapeshellarg($file) . ') DO @ECHO %~zA'); } } return $size; } But this is entirely not the point. The point is that you shouldn't make any assumptions about the input and just blindly use it that way.
  10. Reminds me of Cuil. It was also hyped to be a "Google killer", but I don't think anyone really cares about it anymore.
  11. That's not what I meant with bounds checking. Try to do e.g. ByteSize(pow(1024, 10)) to see what I mean. Moreover, try to do ByteSize(0), which is a valid size that could be returned by e.g. filesize. As I documented in the first function I posted, logarithms are only defined for positive real numbers. Good code will never Again, fewer lines != better code. As a matter of fact, if you use unit testing and code coverage you will artificially increase the code coverage percentage if you cram as much as possible into one line, which makes it more difficult to determine the quality of your testing. That's not to say that more lines leads to better code though. Another important factor is readability and maintainability. If more lines and/or whitespace leads to more readable code then it is much better. Maybe, maybe not. This: filesize('T:\os_images\windows7_7100.0.090421-1700_x64fre_client_en-us_retail_ultimate-grc1culxfrer_en_dvd.iso') outputs -1024139264 on my computer. This is because it overflows the range of a signed integer which is what PHP by default operates with. Another issue is portability. The system you've written may well have checked the size before passing it to a function, but that makes a stronger coupling with that function and your other code, which makes it less portable. By making it do its own job of validating input you're making it more portable and secure. This isn't a concept that should be foreign to you. If you ask the user for his phone number, don't you check that it only contains digits and return an error if not? How about checking if the birth day they enter is a valid date? Surely your users are smart enough to only pass the input you expect, so things like protecting yourself again SQL injections is completely redundant. A function should always be self-contained and not assume anything about its input.
  12. http://en.wikipedia.org/wiki/RAM
  13. Though of course you forget to do a bounds check and will result in incorrect output with too large values. It also does 1,024MB instead of 1GB. I suppose that's just a matter of preference though... Do note that fewer lines != better code. I could cut off many lines from my code if I removed comments, used ternary operators, reduced the return sprintf to 1 line instead of 5 lines, etc. function humanReadableSize($bytes, $precision = 2, $si = false) { $units = $si ? array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') : array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); $unitSize = $si ? 1000 : 1024; if ($bytes < 0) throw new OutOfRangeException('You cannot have negative sizes.'); $x = $bytes == 0 ? 0 : (int) log($bytes, $unitSize); if (!isset($units[$x])) $x = sizeof($units)-1; if ($x == 0 || $precision < 0) $precision = 0; return sprintf('%.' . intval($precision) . 'f %s', $bytes / pow($unitSize, $x), $units[$x]); } I find the former version much more readable though. Indeed. I'm sorry I hijacked the thread
  14. Maybe it's doing some sort of location based result page. The top for me is this page which is absolutely useless.
  15. echo byteConvert(-1); // Warning: Division by zero in file.php on line 7 // 0.00 B echo byteConvert(0); // Warning: Division by zero in file.php on line 7 // 0.00 B echo byteConvert(pow(1024,10)); // Notice: Undefined offset: 10 in file.php on line 7 // 1.00 echo humanReadableSize(-1); // Fatal error: Uncaught exception 'OutOfRangeException' with message 'You cannot have negative sizes.' echo humanReadableSize(0); // 0 B echo humanReadableSize(pow(1024,10)); // 1048576.00 YiB Mine is better. It does bounds checks and throws exceptions on invalid values. See my function two posts up.
  16. http://www.bing.com/search?q=php+help We're #16 http://www.google.com/search?q=php+help We're #1. Google > Bing
  17. I once wrote this function that you can use: <?php /** * Converts a size in bytes to a human readable size using appropriate units. * * @param int $bytes The number of bytes * @param int $precision Floating point output precision * @param bool $si Use SI prefixes (kB, MB, etc.) or IEC prefixes (KiB, MiB, etc.) * @return string * @author Daniel Egeberg <[email protected]> */ function humanReadableSize($bytes, $precision = 2, $si = false) { if (!$si) { $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); } else { $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); } $unitSize = $si ? 1000 : 1024; if ($bytes == 0) { // logarithms are only defined for positive real numbers $x = 0; } else if ($bytes < 0) { throw new OutOfRangeException('You cannot have negative sizes.'); } else { $x = (int) log($bytes, $unitSize); } if (!isset($units[$x])) { // we ran out of units $x = sizeof($units)-1; } if ($x == 0 || $precision < 0) { // a float byte size isn't possible $precision = 0; } return sprintf( '%.' . intval($precision) . 'f %s', $bytes / pow($unitSize, $x), $units[$x] ); } echo humanReadableSize(123456789); // 117.74 MiB
  18. No. Well, it might be in HTTP_REFERER, but I'm not sure. I suppose you can check that out. You shouldn't rely on that though.
  19. You can find info about MySQL fulltext searching here: http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html As for Sphinx and Lucene, I already provided you with links for that. Fulltext searching will be easiest but least efficient way of doing this. It'll of course still be more efficient than using LIKE, but one potential drawback is that it's only available for the MyISAM storage engine.
  20. There is no need for regular expressions in this case: <?php $url = 'http://www.youtube.com/watch?v=wTnChGG2CM0'; parse_str(parse_url($url, PHP_URL_QUERY), $qstring); echo <<<EOF <object width="425" height="344"> <param name="movie" value="http://www.youtube.com/v/{$qstring['v']}&hl=en&fs=1"></param> <param name="allowFullScreen" value="true"></param> <param name="allowscriptaccess" value="always"></param> <embed src="http://www.youtube.com/v/{$qstring['v']}&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed> </object> EOF; ?> Edit: That is of course only in the case you have the URL handy. You'll still need regex for the problem in your most recent post. Just wanted to point out that PHP has built-in functions for parsing and generating URLs.
  21. anupamsaha, you might want to read all the responses before replying. GingerRobot provided that solution almost an hour ago.
  22. That LIKE is slow and doesn't scale well. You'd want to look into using some sort of index instead. You could use MySQL's full text searching (only in MyISAM), Sphinx, or Lucene (one PHP implementation is Zend_Search_Lucene). This forum uses Sphinx and search queries complete in under a second searching in 841,296 (and counting) posts.
  23. You should also check that an array index exists before you try to read from it. Either isset, empty or array_key_exists can help you with that.
  24. The code that is generating the XLS is doing it wrong obviously.
  25. How are you searching now?
×
×
  • 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.