Categories
blog fun

Hi, my name is Robert’); DROP TABLE Students;–

Exploits of a Mom:

Teacher: “Hi, this is your son’s school. We’re having some computer trouble.”
Mom: “Oh, dear – Did he break something?”
Teacher: “In a way… Did you really name your son Robert’); DROP TABLE Students;–?”
Mom: “Oh, yes. Little Bobby Tables we call him.”
Teacher: “Well, we’ve lost this year’s student records. I hope you’re ¬†happy.”
Mom: “And I hope you’ve learned to sanitize your database inputs.”

[ad name=”Adsense – text only”]
Source: xkcd.com/327

Categories
code

Get Accurate Script Execution Time in PHP

This small code can be quite helpful if you need to find out what is taking so long to load in your script(s).
It will determine the time taken for your PHP script(s) to execute, accurate to 0.000000000000001 seconds.

[ad name=”Adsense – text only”]

The Code

// put this at the top of your page/script
$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$starttime = $exectime;

/*
 *   place your script(s) to here
 */


// put this at the bottom of your page/script
$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$endtime = $exectime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds";

…and that’s all! Happy debugging!

Categories
blog fun

I Am The Most Powerful Genie In The World

A programmer is walking along a beach and finds a lamp. He rubs the lamp and a genie appears. “I am the most powerful genie in the world. I can grant you any wish, but only one wish.”

The programmer pulls out a map, points to it and says, “I’d want peace in the Middle East.”

The genie responds, “Gee, I don’t know. Those people have been fighting for millennia. I can do just about anything, but this is likely beyond my limits.”

The programmer then says, “Well, I am a programmer and my programs have lots of users. Please make all my users satisfied with my software and let them ask for sensible changes.”

At which point the genie responds, “Um, let me see that map again.”

[ad name=”Adsense – text only”]

Categories
code

How To Recover Your MySQL root Password

I just needed to recover a lost MySQL root password on a clients server recently and thought I’d share the method I used.

[ad name=”Adsense – text only”]

Actually it’s not a method for recovering but you can change the forgotten password to a new one.
All you need is to follow this 6 easy steps:

Step 1: Stop the mysql service

# /etc/init.d/mysql stop

Expected Output:

Stopping MySQL database server: mysqld.

Step 2: Start the MySQL server without password

# mysqld_safe --skip-grant-tables &

Expected Output:

[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step 3: Connect to your MySQL server using the MySQL client

# mysql -u root

Expected Output:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Step 4: Setup a new MySQL password for the root user

mysql> use mysql;
mysql> update user set password=PASSWORD("YOUR-NEW-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit;

Expected Output:

Database changed

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Bye

Step 5: Stop the MySQL Server

# /etc/init.d/mysql stop

Expected Output:

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

[1]+  Done                    mysqld_safe --skip-grant-tables

Step 6: Start the MySQL server and test it

# /etc/init.d/mysql start
# mysql -u root -p

Expected Output:

Starting service MySQL         done

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is xx
Server version: x.x.xx XXXXX MySQL RPM

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Now you should be all done!
I hope this helps you as much as it did for me.