SQL injection that gets around mysql_real_escape_string()

The short answer is yes, yes there is a way to get around mysql_real_escape_string(). #For Very OBSCURE EDGE CASES!!! The long answer isn’t so easy. It’s based off an attack demonstrated here. The Attack So, let’s start off by showing the attack… mysql_query(‘SET NAMES gbk’); $var = mysql_real_escape_string(“\xbf\x27 OR 1=1 /*”); mysql_query(“SELECT * FROM test … Read more

PHP parse/syntax errors; and how to solve them

What are the syntax errors? PHP belongs to the C-style and imperative programming languages. It has rigid grammar rules, which it cannot recover from when encountering misplaced symbols or identifiers. It can’t guess your coding intentions. Most important tips There are a few basic precautions you can always take: Use proper code indentation, or adopt … Read more

How do I send a POST request with PHP?

CURL-less method with PHP5: $url=”http://server.com/path”; $data = array(‘key1’ => ‘value1’, ‘key2’ => ‘value2’); // use key ‘http’ even if you send the request to https://… $options = array( ‘http’ => array( ‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”, ‘method’ => ‘POST’, ‘content’ => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) … Read more

How do I get the query builder to output its raw SQL query as a string?

Use the toSql() method on a QueryBuilder instance. DB::table(‘users’)->toSql() would return: select * from `users` This is easier than wiring up an event listener, and also lets you check what the query will actually look like at any point while you’re building it. Note: This method works for query builder or Eloquent, however toSql() is … Read more

What is the best collation to use for MySQL with PHP? [closed]

The main difference is sorting accuracy (when comparing characters in the language) and performance. The only special one is utf8_bin which is for comparing characters in binary format. utf8_general_ci is somewhat faster than utf8_unicode_ci, but less accurate (for sorting). The specific language utf8 encoding (such as utf8_swedish_ci) contain additional language rules that make them the … Read more

How to calculate the difference between two dates using PHP?

I suggest to use DateTime and DateInterval objects. $date1 = new DateTime(“2007-03-24”); $date2 = new DateTime(“2009-06-26”); $interval = $date1->diff($date2); echo “difference ” . $interval->y . ” years, ” . $interval->m.” months, “.$interval->d.” days “; // shows the total amount of days (not divided into years, months and days like above) echo “difference ” . $interval->days … Read more

How do I implement basic “Long Polling”?

It’s simpler than I initially thought.. Basically you have a page that does nothing, until the data you want to send is available (say, a new message arrives). Here is a really basic example, which sends a simple string after 2-10 seconds. 1 in 3 chance of returning an error 404 (to show error handling … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)