laserlight wrote:If you really want to follow HTTP/1.1, the URL should be an absolute URL. Oh, and it is good practice to have an exit or a die after a location header is sent.
Yeah, that's very true. You can use information from the $_SERVER array to generate the absolute URL.
I'd also like to point out that the original code is vulnerable to SQL injection attacks. Take a look at this code extract:
// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];
$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");
//$result2=mysql_query($sql);
Here the data is obtained from $_POST, placed into variables and then immediately inserted into the SQL statement. There's a good description of SQL injection here: http://www.acunetix.com/websitesecurity/sql-injection.htm
Oh, and since we're all tied up on coding standards, I'd like to point out that this code will generate NOTICE errors if the relevant data is not provided via POST:
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];
An improved version could use the ternary conditional operator (described on my own website: http://www.scross.co.uk/tips/59/ ), like so:
$myusername=isset($_POST['myusername']) ? $_POST['myusername'] : '';
$mypassword=isset($_POST['mypassword']) ? $_POST['mypassword'] : '';
$myusertype=isset($_POST['myusertype']) ? $_POST['myusertype'] : '';
You should probably use this whenever you're obtaining data from any of the superglobals ($POST, $GET, $_SESSION etc.).