Tuesday, August 6, 2013

Apostrophe (') Gets Censored After Inserting Into MySQL. How to Fix it?

I think MySQL doesn't like apostrophe or '. When inserting into MySQL, the apostrophe goes missing. How to fix this? Simple. Here's it is: $text = "My car's mirror is broken!"; $text2DB = addslashes($text); mysql_query("INSERT INTO ... $text2DB ... // complete the MySQL INSERT INTO action here PHP's addslashes() function is enough to solve this problem. It will add slashes when necessary automatically. Isn't that ne...
Read More »

From Your Check Out Form to Paypal's Note to Seller

If you want to add note to the Paypal seller from your check out form or shopping cart, you need to add the cn input name and value in the post form before submitting to Paypal. Something look like: <input type=hidden name=cn value="Please ship directly to my dorm room"> If everything is done correctly, the "note to seller" will appear in the Paypal check out form. ...
Read More »

Auto Login using PHP stream_context_create() and file_get_contents()

The following is just a rough idea of how to log in to a website using PHP. If the target website is owned by you, you should know how it is done. If not, you may need to contact the web administrator before doing so. The web site owner may not like it. The main idea here is to make the login and grab the data out with just one push button to save all the hassels to log in manually. It is advised to make it completely legal before you even try it: $postdata = http_build_query(  array(      'postUserName'...
Read More »

My Javascript and PHP Way to Extract the File Extension

Javascript: var extension; var filename = "test.my.txt"; var ext = filename.split("."); if (ext[1] != "") {      extension = ext[ext.length-1]; } // extension will contain "txt" PHP: $fullfilename = "test.my.txt"; preg_match("/(.+)\.([^\.]+)$/",$fullfilename,$match); $filename = $match[1]; $extension = $match[2]; // $extension will contain "txt" I think the codes are very self-explanatory. Enjoy!!...
Read More »

Javascript and PHP Cookie Expiration Setting Technique

Javascript: var hour = 24; // expire in 24 hours var tm1 = new Date(); var tm2 = new Date(tm1.getTime()+3600000*hour); // 60*60*1000 = 3600000 ms var exp = "expires = " + tm2.toUTCString(); document.cookie = 'cookiename = cookievalue;'+exp; PHP: $hour = 24; setcookie("cookiename","cookievalue",time()+(3600*$hour)); For PHP technique, it has a problem. The time() gets the time of the server instead of the browser. In order to get the accurate expiration timing, one needs...
Read More »

My Javascript to Guess Processor's Speed

Updated on 5th of February, 2014: There is an updated version for this posting here. This is necessary when your web page runs a lots of animation using javascript. If the target browser is slow in computing speed, it is advisable to reduce the amount of animation to run on the machine. Here's my simple way to check the speed of a computer using simple Javascript: <script> var count; var d = new Date(); var startTime = d.getTime(); for (i=0; i<=1000000; i++) { count++; } var...
Read More »

Monday, August 5, 2013

My Javascript Function to Show UTC Time Zone of Your Browser/Computer

Your computer has its own time zone setting as well as the web host server. Most of the time they are quite different. United States alone has three different time zones. It is crucial to get the time zone offset off the browser than the server as the time zone is something personal rather than a server sitting on a fixed location that tells nothing about the visitors possibly from the other side...
Read More »

Sunday, August 4, 2013

JQuery Close-Up: Is it a Good Idea?

JQuery popularity in web development nowadays is similar to Facebook in social network. Developers and programmers love to use it. The coding is simple and brisk but most people use it just to perform simple tasks on the web pages such as changing the DOM element styles, ie. color, opacity and location. Many use it to perform tasks that can be easily emulated in conventional Javascript and I think...
Read More »

Modifying Your ASP Code to ASPX VB.Net

This could have been a very old topic as ASP (VB) has been phased out long ago and VB.Net is almost obsolete compared with C#. Although VB and VB.net are using the same programming language, the way they work on a web page is vastly different. Anyway, let's go with the fun of migrating from one programming environment to another. ASP (VB) <% . . Dim orange orange = "apple" . . . %> <html> <body> . . ...<%=orange%> . . . . . . </body> </html> ASPX...
Read More »