
dcro2
Members-
Posts
489 -
Joined
-
Last visited
Never
Everything posted by dcro2
-
From the money_format manual page:
-
"preg" in search string returns all results from mysql
dcro2 replied to cindreta's topic in PHP Coding Help
I don't like guessing so much. Could you post some code please? -
PHP MySQL Select varbinery Field output wrong
dcro2 replied to imperium2335's topic in PHP Coding Help
Piwik uses inet_pton to convert an ip string to binary and inet_ntop to convert it back. "WHERE location_ip = '".inet_pton('81.157.3.249')."'" If you have Windows or PHP < 5.1 (PHP >= 5.3 includes it with Windows), it also includes some functions you can use instead: /** * Converts a packed internet address to a human readable representation * * @link http://php.net/inet_ntop * * @param string $in_addr 32-bit IPv4 or 128-bit IPv6 address * @return string|false string representation of address or false on failure */ function php_compat_inet_ntop($in_addr) { // in case mbstring overloads strlen function $strlen = function_exists('mb_orig_strlen') ? 'mb_orig_strlen' : 'strlen'; $r = bin2hex($in_addr); switch ($strlen($in_addr)) { case 4: // IPv4 address $prefix = ''; break; case 16: // IPv4-mapped address if(substr_compare($r, '00000000000000000000ffff', 0, 24) === 0) { $prefix = '::ffff:'; $r = substr($r, 24); break; } // IPv4-compat address if(substr_compare($r, '000000000000000000000000', 0, 24) === 0 && substr_compare($r, '0000', 24, 4) !== 0) { $prefix = '::'; $r = substr($r, 24); break; } $r = str_split($r, 4); $r = implode(':', $r); // compress leading zeros $r = preg_replace( '/(^|:)0{1,3}/', '$1', $r ); // compress longest (and leftmost) consecutive groups of zeros if(preg_match_all('/(?:^|(0(:|$))+/', $r, $matches)) { $longestMatch = 0; foreach($matches[0] as $aMatch) { if(strlen($aMatch) > strlen($longestMatch)) { $longestMatch = $aMatch; } } $r = substr_replace($r, '::', strpos($r, $longestMatch), strlen($longestMatch)); } return $r; default: return false; } $r = str_split($r, 2); $r = array_map('hexdec', $r); $r = implode('.', $r); return $prefix . $r; } /** * Converts a human readable IP address to its packed in_addr representation * * @link http://php.net/inet_pton * * @param string $address a human readable IPv4 or IPv6 address * @return string in_addr representation or false on failure */ function php_compat_inet_pton($address) { // IPv4 (or IPv4-compat, or IPv4-mapped) if(preg_match('/(^|([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/i', $address, $matches)) { for($i = count($matches); $i-- > 2; ) { if($matches[$i] > 255 || ($matches[$i][0] == '0' && strlen($matches[$i]) > 1)) { return false; } } if(empty($matches[1])) { $r = ip2long($address); if($r === false) { return false; } return pack('N', $r); } $suffix = sprintf("%02x%02x:%02x%02x", $matches[2], $matches[3], $matches[4], $matches[5]); $address = substr_replace($address, $matches[1] . $suffix, strrpos($address, $matches[0])); } // IPv6 if(strpos($address, ':') === false || strspn($address, '01234567890abcdefABCDEF:') !== strlen($address)) { return false; } if(substr($address, 0, 2) == '::') { $address = '0'.$address; } if(substr($address, -2) == '::') { $address .= '0'; } $r = explode(':', $address); $count = count($r); // grouped zeros if(strpos($address, '::') !== false && $count < { $zeroGroup = array_search('', $r, 1); // we're replacing this cell, so we splice (8 - $count + 1) cells containing '0' array_splice($r, $zeroGroup, 1, array_fill(0, 9 - $count, '0')); } // guard against excessive ':' or '::' if($count > 8 || array_search('', $r, 1) !== false) { return false; } // leading zeros foreach($r as $v) { if(strlen(ltrim($v, '0')) > 4) { return false; } } $r = array_map('hexdec', $r); array_unshift($r, 'n*'); $r = call_user_func_array('pack', $r); return $r; } `idvisit` is an INT(10) so you shouldn't have problems with that. -
You're probably exceeding the default timeout of 30 seconds. See set_time_limit. You can't really speed it up any more than it is. Maybe curl might help.
-
Just, no. PHP is a server side processor. Everything happens on the server unless you decide to output the file to the browser.
-
Can't connect to MySQL server on 'localhost' (10061
dcro2 replied to Pieter Lategan's topic in PHP Coding Help
Please provide more info like your host, how you created this database or if you have access to phpMyAdmin. Have you even set up a database? -
I think you mean: mysql_query(sprintf("UPDATE members SET Age = '%s'", mysql_real_escape_string($age))) You might want to add a WHERE clause to that though, or you'll update all the rows in that table. For example: UPDATE members SET age = '12' WHERE username = 'droidus'
-
You're welcome!
-
User agents aren't an exact science, they can be spoofed and there's so many it's very hard to be 100% right. I'm not sure what user agent that browser has, but the code from that page doesn't seem to mention Dolphin so it's probably not set to detect it.
-
fgets doesn't take out the ending newline in each line: Which is why it never matches "non-taxable", it's actually "non-taxable\n". A nice trim should take care of it: list($info, $amount, $tax) = explode(":" , trim($newLine));
-
Right, just put your own error handling code in there. And don't hold me accountable if it doesn't work
-
But PLEASE offer an option to view the full site if you're going to force a mobile view on somebody when they first go into your site.
-
There's no 'FILES' request method, it all comes through POST. You should use $_FILES to check if a file was uploaded. For example: if($_FILES['image']['error'] !== UPLOAD_ERR_OK || $_FILES['image']['size'] == 0) { //Something went wrong } Feel free to do a print_r on $_FILES so you can see the entire structure (or refer here). Here's some error constants: http://darklaunch.com/2009/05/01/php-file-upload-error-codes-upload-err-ok
-
Have you tried outputting $tax to see what it actually contains? Because if these fields are wrapped in double quotes then $tax still has double quotes inside it, and it will not match "non-taxable", but will match "\"non-taxable\"" (or '"non-taxable"'). PS: please use or tags (although, you can't bold inside them).
-
PHP MySQL Select varbinery Field output wrong
dcro2 replied to imperium2335's topic in PHP Coding Help
What exactly should `idvisit` contain? Another IP address like `location_ip`? -
I personally can't understand what you want to do. You might want to try explaining your problem better to get a response.
-
You want to create a whole new database for each tracker? Why not just add a 'tracker_id' column or something like that to these tables?
-
Parse error: syntax error, unexpected T_LOGICAL_OR
dcro2 replied to yogen's topic in PHP Coding Help
On line 288, you're using single quotes to wrap the string but you're also using them inside the string. You need to escape them with backslashes: echo '... onfocus="this.value=\'\';" ...'; -
In your code, if either the connection fails or the select fails, your script outputs mysql_error() and then exits. It never gets to the part where you check if either of them failed. Take a look at the manual page for die (which is actually exit).
-
If the sites these images are on aren't yours, this is what we call hotlinking. And even worse than normal hotlinking, you don't let browsers cache the images which results in more bandwidth usage for you and the site the image is on. Seriously, just don't do it.
-
Put this at the top of your script: error_reporting(E_ALL); ini_set('display_errors', 1); You may want to try passing ./exec.pl to the perl executable itself.
-
Here's a simple example of what you could do using jQuery: <script src="jquery.js"></script> <script> function checkAnswer(id) { selected = $("input[name=answer_"+id+"]:checked").val(); $.get("checkanswer.php", {id: id}, function(data) { alert("Your answer: "+selected+"\n\nCorrect Answer: "+data); }); } </script> <input type="radio" name="answer_123" value="A" checked="checked">A</input> <input type="radio" name="answer_123" value="B">B</input> <input type="radio" name="answer_123" value="C">C</input> <input type="radio" name="answer_123" value="D">D</input> <a href="#" onclick="checkAnswer(123); return false;">Check Answer</a> Just code getanswer.php to take $_GET['id'] and get its answer from the database, assuming each question has some kind of unique id.
-
No, there's no events. When you go to a webpage, your browser requests the page from the web server, Apache for example. If the page is written in PHP, Apache then calls on PHP to process that page and then sends you whatever code PHP generated. After that the page in your browser is a done deal, no changes and no more communication to the web server. If you want to replace parts of the page or call a PHP script, you'll have to use Javascript to request that page from the server while your browser keeps displaying the same page.
-
Take a look at this line: document.forms[0].submit(); What that's doing is basically submitting the first form in the document, hence [0], the first index. The first form also belongs to the first record. If all you want to do is submit the form then what you could do instead is change the OnChange to something like: onchange="this.form.submit();"
-
This should probably be in one of the database forums, but I think MySQL triggers would be what you want. They basically run after whatever event you want occurs, so you can add up the points. http://www.rustyrazorblade.com/2006/09/mysql-triggers-tutorial/