Sunday, November 30, 2014

.htaccess Handling

.htaccess Handling

errorDocument 400 http://www.web.com
errorDocument 401 http://www.web.com
errorDocument 403 http://www.web.com
errorDocument 404 http://www.web.com
errorDocument 500 http://www.web.com

# Disable Directory Browsing
Options All -Indexes

RewriteEngine On
RewriteCond %{HTTP_HOST} ^web.com
RewriteRule (.*) http://www.web.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^subdomain\.youwebsite\.com$
RewriteCond %{REQUEST_URI} !^/subdomain_folder/
RewriteRule (.*) /subdomain_folder/$1

RewriteCond %{HTTP_HOST} ^oldwebsite.com
RewriteRule (.*) http://www.newwebsite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.oldwebsite\.com

RewriteRule (.*) http://www.newwebsite.com/$1 [R=301,L]

Add New Column in MySQL Table

Add New Column in MySQL Table

ALTER TABLE yourtable ADD q6 VARCHAR( 255 ) after q5

Add Delete Cookie Values

Add Cookie Values

$remember = $_POST['check'];
if($remember)
{
$expire=time()+60*60*24*30;
setcookie("user", $id, $expire);
}
else
{
setcookie("user", "", time()-3600);
}

Delete Cookie Values

setcookie("user", "", time()-3600);


Upload and Re-size Images

Upload and Re-size Images

<form role="form" method="post" action="uppropic.php" enctype="multipart/form-data">
                                    <div class="box-body">
                                        <div class="form-group">
                                            <label for="exampleInputFile">File input</label>
                                            <input type="file" id="exampleInputFile" name="file">
                                            <p class="help-block"></p>
                                        </div>
                                     
                                    </div><!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" class="btn btn-primary">Upload</button>
                                    </div>
                                </form>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


<?php

 define ("MAX_SIZE","4000");

 $errors=0;

 if($_SERVER["REQUEST_METHOD"] == "POST")
 {
        $image =$_FILES["file"]["name"];
 $uploadedfile = $_FILES['file']['tmp_name'];

  if ($image)
  {
  $filename = stripslashes($_FILES['file']['name']);
        //$extension = getExtension($filename);
     
        $extension = pathinfo($image, PATHINFO_EXTENSION);
     
  $extension = strtolower($extension);
 if (($extension != "jpg") && ($extension != "jpeg")
&& ($extension != "png") && ($extension != "gif"))
  {
echo ' Unknown Image extension ';
$errors=1;
  }
 else
{
   $size=filesize($_FILES['file']['tmp_name']);

if ($size > MAX_SIZE*1024)
{
 echo "You have exceeded the size limit";
 $errors=1;
}

if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}

list($width,$height)=getimagesize($uploadedfile);

$newwidth=250;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);

$newwidth1=100;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

$newwidth2=50;
$newheight2=($height/$width)*$newwidth2;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
 $width,$height);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,
$width,$height);

imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$newheight2,
$width,$height);

$uxi=rand(9,999);

//$cid=$uxi.$cid;

$mypphoto="propic-".$uxi.$cid.".".$extension;

$filename = "propic/".$mypphoto;
$filename1 = "propic/100/".$mypphoto;
$filename2 = "propic/50/".$mypphoto;

imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);
imagejpeg($tmp2,$filename2,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
imagedestroy($tmp2);
}
}
}
//If no errors registred, print the success message

if (($extension != "jpg") && ($extension != "jpeg")
&& ($extension != "png") && ($extension != "gif"))
  {
header("location:./?error22");
  }
 else
 {

 $sql2="UPDATE users SET photo='$mypphoto' WHERE id = '$cid'";
$result2=mysql_query($sql2);

if($result2)
{

if($userphoto=="dpic.png")
{
$userphoto="";
}
else
{
if(file_exists("propic/$userphoto"))
{
unlink("propic/$userphoto");
}

if(file_exists("propic/50/$userphoto"))
{
unlink("propic/50/$userphoto");
}

if(file_exists("propic/100/$userphoto"))
{
unlink("propic/100/$userphoto");
}

}
header("location:./");



//header("location:./");
}
else
{
header("location:./?error");
//echo "Error...";
}

}
 ?>

MySQL Table Connecting

MySQL Table Connecting

<?php

$db_host = "localhost";
$db_username = "aaaaaaaa";
$db_password = "aaaaaa";
$db = "aaaaaaa";



   mysql_connect( $db_host, $db_username, $db_password )
      or die( "Error! Could not connect to database: " . mysql_error() );
 
   mysql_select_db( $db )
      or die( "Error! Could not select the database: " . mysql_error() );





?>


Delete MySQL Table Data

Delete MySQL Table Data

if($cid!=""){
$id=$_REQUEST['id'];
$sql="DELETE FROM customers WHERE id=$id";
$result=mysql_query($sql);

if($result)
{
header("location:customers.php?delete=true");
}

}

Update MySQL Table Values

Update MySQL Table Values

$query = "UPDATE `customers` SET
`fname`='$fname',
`lname`='$lname',
`email`='$email',
`phone`='$mobile',
`dd`='$dd',
`dm`='$dm',
`dy`='$dy',
`address`='$address'
WHERE id='$id'";
$results = mysql_query( $query );
if($results)
{
echo "Successfull";

}