Javascript to confirm delete

You can use simple javascript code to ask for confirmation before deleting records in db whether you are using PHP or ASP or whatever  web scripting

Here’s the code

<a href=“delete.page?id=1″ onclick=“return confirm(’Are you sure you want to delete?’)”>Delete</a>

source:
http://psacake.com/web/iw.asp

November 11th, 2007 by azwan in Javascript | No Comments

PHP: Random strings or password

I was looking for a code to generate random password to be given to a newly registered user for my system.

Maybe you can use it as verification code for them to enter your system for the first time and validate that their provided e-mail is valid.

Here’s the code

<?php

/** * The letter l (lowercase L) and the number 1 * have been removed, as they can be mistaken * for each other. */

function createRandomPassword() {

    $chars = “abcdefghijkmnopqrstuvwxyz023456789″;    srand((double)microtime()*1000000);    $i = 0;    $pass = ;

    while ($i <= 7) {        $num = rand() % 33;        $tmp = substr($chars, $num, 1);        $pass = $pass . $tmp;        $i++;    }

    return $pass;

}

// Usage$password = createRandomPassword();echo “Your random password is: $password”;

?> 


Source: http://www.totallyphp.co.uk/code/create_a_random_password.htm

Tags: , , ,


March 12th, 2007 by azwan in PHP | No Comments

Javascript multiple menu selection

I’ve been looking for javascsript drop down menu. It works like this.

When you select on an option for first menu, it will invoke list of another menu. Then you can make selection on the other menu and so on.

Click here for tutorial

Tags: , ,

March 6th, 2007 by azwan in Javascript | No Comments

Javascript - form validation

Form validation using javascript is the most effective ways. With this you can block any attempt to send a form without giving a valid value.

i’ve found a class written for this purpose. All you need is to include the file (javascript file .js), create object and add validations under your input form.

Form validation website

Tags: ,

February 4th, 2007 by azwan in Javascript | No Comments

Installing IIS in Windows XP Home Edition

I’ve just bought a new notebook but the package only comes with Windows XP Home Edition. It is a problem for me to run IIS (so that I can use ASP) on the operating system.

So I looked around and found few sites that have work around to solve this problem. Here is one of the sites that have step by step tutorial for the work around.

http://adamv.com/dev/articles/iis-on-xp-home

Another option is to download Abyss web server

December 29th, 2006 by azwan in ASP | No Comments

3 ways to include CSS (cascading style sheet)

There are 3 ways to include CSS to your HTML code

1. Import a CSS file

<link href=”style.css” rel=”stylesheet” type=”text/css”>

2. Place CSS for the page in header part

<style>
    .style1 {font-family:Arial, Helvetica, sans-serif; }
</style>

3. Define CSS in HTML tag

<p style=”font-family:Arial, Helvetica, sans-serif”>

Tags: , ,

December 25th, 2006 by azwan in CSS, PHP | No Comments

Secure the PHP form

One day I want to log on to my hosting account, but failed. Then I e-mailed web hosting support to help. I got a reply stated that one of my file (contact form) is not secure that someone from outside can execute and send spam email with the script.

To secure the script, you need to check the script is executed within your domain and from the provided form.

So here is the code, place it before you execute the send to mail script.

if(!(isset($_SERVER[’HTTP_REFERER’]) && !empty($_SERVER[’HTTP_REFERER’]) && stristr($_SERVER[’HTTP_REFERER’],$_SERVER[’HTTP_HOST’]))) {
    print “Msg not sent.”; exit;
}

or a simpler one (just check it is submitted form a form)

if (!isset($_POST[’Submit’])) {
    print ” Msg not sent’; exit;
}

If else statement is not just if else. You must think

  1. security (else statement for less secure operation)
  2. execution time (top if statement is the most frequently executed)

December 24th, 2006 by azwan in PHP | No Comments

PHP - validate required form

It is quite a tedious job to alter javascript or PHP each time you have a new form. Here is a simple way to do it.

In the form include this line of code

<input type=”hidden” name=”required” value=”name,email,phone”>

In the PHP (processing file)

$checkArray= explode(”,”,$_POST[’required’]);
while(list($check) = each($checkArray))
{
    if(!$$checkArray[$check]) {
    $error .= “You have not filled this required field: <b>$checkArray[$check]</b>.<br>”;
        }
}

if ($error)
    echo ‘Error in form submission’ .$error; // and stop process
else
    //process the form

So you just need to modify single line in your form file. All the checking will be done automatically in the PHP file.

Note: The code above is not tested yet.

Tags: ,

December 24th, 2006 by azwan in PHP | No Comments

Time to learn AJAX

AJAX (stands for Asynchronous Javascript And XML) is getting popular lately. It is not a new technology though.

Web application has lots of advantages over client application. With web application, people don’t have to install the application, easy to develop and manage.

A major disadvantages is it is bit slow, need to reload whole page, and less user friendly in certain part. All these mainly because it is a server-side application where the browser need to communicate a lot with server.

AJAX overcomes this problem. It only send portion of the page and does not reload the whole page.

I’ve been looking for quick tutorial to kick start with AJAX.

Read more about AJAX

Tags: ,

December 23rd, 2006 by azwan in AJAX | No Comments

PHP - random quotes

It is a good idea to have a random quotes on your website front page.

Actually it is as simple as having few lines of code with a text file that store all the quotes.

Here is the code to randomly read and display the quotes.

$quotes = file(’quotes.txt’);
$rand = rand(0, count($quotes) - 1);
echo $quotes[$rand];

That’s it!

December 23rd, 2006 by azwan in PHP | No Comments