When you make a PHP script, but you do not know how PHP is configured on the server the script is being executed on, you might not know whether or not to add or strip quotes from get and post data. Notice that the $_FILES array is not affected by magic quotes.
Warning: one should handle slashes on keys also, not only values. See first comment.
Here is a script that strips away magic quotes, if they were added:
- < ?
- if(get_magic_quotes_gpc()) {
- function undo_magic_quotes($array) {
- return is_array($array) ? array_map('undo_magic_quotes', $array) : stripslashes($array);
- }
- $_GET = undo_magic_quotes($_GET);
- $_POST = undo_magic_quotes($_POST);
- $_COOKIE = undo_magic_quotes($_COOKIE);
- $_REQUEST = undo_magic_quotes($_REQUEST);
- }
- ?>
And likewise, here is a script that adds magic quotes, if they were not already applied:
Continue reading →
After installing WordPress for this blog, I realized that I was forced to use the stupid TinyMCE WYSIWYG editor. I smiled when i found out that I was able to set a HTML editor only flag in my account settings. But this did not turn the editor into a pure HTML editor, since every line i wrote was replaced by <p>{the_line}<p>, which is not practical when you want to paste programming code.
Here is how you disable this unacceptable behavior the easy way (WP kindly asks you to find a plugin that undo the paragraphs, but you know…).
Continue reading →
Sometimes a parent table have more than one table with multiple references to a field in the parent table. Then the question is how to count references from more than one table in a single query. I have found 5 different ways to achieve this result, and therefore I have run a few tests, to see which was better.
To test this I made this small PHP script, that creates a parent table and child table. Then a loop populates the tables with 1,000 parent rows, approximately 15 children of type 1 and approximately 75 children of type 2. This is done before each query, to make sure that all queries have the same conditions.
Continue reading →
Hello world! This blog is simply named 5p, because it was one of the few domains left with less than three characters. I chose 5p among these, since p can stand for many good things, for example: Professionalism, Problemsolving, Planning, Procedures or Performance. There are actually 3,205 different words that starts with the letter p in the danish language, without conjugations.
Actually 5p was the only one left out of 6 domains. Unfortunately it is not easy to search for domain names, so to make this conclusion i made what some might call a “dictionary attack” at the .dk provider. I simply calculated all combinations of danish domains with 2 characters and looked them up, with a small php script i executed in a cmd prompt. The other 5 domains left was (notice that the first two starts with zero, not the letter o):
Continue reading →
Posted in PHP
|
Tagged .dk, Blog, PHP, Script
|