Skip to main content

Posts

Showing posts from October, 2013

JavaScript md5 encoding

MD5 = function(data) {     // convert number to (unsigned) 32 bit hex, zero filled string     function to_zerofilled_hex(n) {             var t1 = (n >>> 0).toString(16)         return "00000000".substr(0, 8 - t1.length) + t1     }     // convert array of chars to array of bytes     function chars_to_bytes(ac) {         var retval = []         for (var i = 0; i < ac.length; i++) {             retval = retval.concat(str_to_bytes(ac[i]))         }         return retval     }     // convert a 64 bit unsigned number to array of bytes. Little endian     function int64_to_bytes(n...

PHP use of form and retrieve form data

<html> <body> <form action="welcome.php" method="post"> <label for="fname">Name: </label><input type="text" name="fname" id="fname"/> <label for="age">Age: </label><input type="text" name="age" id="age"/> <button type="submit">Continue</button> </form> </body> </html> welcome.php: <html> <body> Welcome <?php echo $_POST['fname']; ?>!<br/> You're <?php echo $_POST['age']; ?> years old!<br/> </body> </html>

PHP create directory

<?php if(isset($_GET["name"]) mkdir("php/".$_GET["name"]); ?> <html> <head> <title>Create Directory</title> </head> <body> <form action="?"> <input type="text" name="name" placeholder="Directory Name"/><br> <button type="submit">Create</button> </form> </body> </html>

PHP link image from a directory

The following code is to link images from your php directory. "photo.php" acts in two ways. The "src" attribute should be like "src=photo.php?view=1&default=0&id=1". When "view=0" is used it is to tell the script that the photo is to be used within a page. When "view=1" is used it is to tell the script that the page, "photo.php", is to be loaded and other options are shown to the user. Here, "id" specifies the image that is to be shown on the page. And "default=1" specifies that the image isn't user uploaded but images to be used in the sites. The use of above mentioned things can be seen in the same following code: <?php session_start(); $id = $_GET["id"]; $default = ""; if (isset($_GET["default"]))     $default = $_GET["default"]; $photo_path = "/php/account/"; $view = NULL; if (isset($_GET["view"]))     $view = $_GET[...

PHP captcha code generation, submission and verification

PHP Code Submission & Verification: The following code is for the submission and verification of the captcha code entered by user and redirect the user to an other page. <?php print '<html><head><link type="text/css" rel="stylesheet" href=" http://localhost/php/account/photo.css"/><title>Captcha</title></head><body>' ; $error = NULL; if (isset($_REQUEST['confirm_code'])) {     if (isset($_COOKIE['Captcha'])) {         list($Hash, $Time) = explode('.', $_COOKIE['Captcha']);         if (md5("OASDOIJQWOIJDASDOI" . strtoupper($_REQUEST['confirm_code'] . $_SERVER['REMOTE_ADDR'] . $Time)) != $Hash) {             $error = '<marquee behavior="slide" direction="up" width="100%" height="2.5%" style="text-align: center;" id="pop-up"><div width="100%" style="text-a...

PHP upload an image and set it as the profile photo of the user

I'm using WampServer for running PHP scripts offline. This code is to upload an image and set it as profile photo of the user. So, to store the data I've created a directory "account" & "account/users/" to store my php scripts and user's data and information.  PHP: <?php session_start(); if (isset($_POST["file"]) || isset($_GET["file"]) || isset($_GET[md5("upload")])) {     $allowedExts = array("gif", "jpg", "jpeg", "png");     $temp = explode(".", $_FILES['file']['name']);     $extension = end($temp);     $email = "";     if (isset($_SESSION["email"]))         $email = $_SESSION["email"];     $f = "/php/account/users/$email/profile/";     if ((($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/jpg") || ($_FILES['file'][...