Monday, July 27, 2009

Proxy setting in apache or Url with out port number

Here you can see the example for proxy setting in your apache or redirecting your site in to other site with in your apache configuration

You may facing problem of getting port number in url when your having same server with different port usually by default your server will be set to port 80 if you are having a different site on same server but with different port if you try to run site u will get the port number in url this may be looking ugly. So here is solution to over come this problem

The below example shows you how do proxy setting in apache

Ste1. enable proxy module in side your apache configuration file (http.conf) in side conf folder

LoadModule proxy_module modules/mod_proxy.so

#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

LoadModule proxy_connect_module modules/mod_proxy_connect.so

LoadModule proxy_http_module modules/mod_proxy_http.so

Step2. paste the following code inside http.conf

ProxyRequests off


Order deny,allow
Allow from all


ProxyPass /site1 http://www.example.com/stie1

Like this you can have different site in single port number first time when you enter www.example.com this is basic site if user mention www.example.com/stie1 then this should goes to different application

How to remove port number from url

Here you may be getting your site url like this example:8222/index.php problem here is you may be having different site on same server but with different port number .but this looks ugly… to remove the port number from the url use the same method of proxy


Order deny,allow
Allow from all


ProxyPass /site1 http://example:8222/stie1

When you enter the www.example.com this proxy setting will redirect your site to the site1 folder but the url name remain same as www.example.com

Tuesday, July 21, 2009

How to Create image file and get image Resource like image height and width in PHP

How to Create image file and get image Resource like image height and width in PHP

In some case u may need the image height or width or image resolution in php function to check weather these image suites with your site or not…..

The following function gives the list

-width of image

-height of image

-resolution of the image

-how to create the image file inside your php

-how to get the image Resource

-hoe to get Extension of image file etc….

To get all this image related resource call the below function

echo $image_width = getImageWidth(/image/path/image.jpg)//here the correct image path should give

function getImageWidth($filename){

if(file_exists($filename))

{

$ext = getExtension($filename);//to get the image extension its defined bellow

if(!$ext)

return 0;

$img_src = getImageResource($ext, $filename);//to get the image resource its defined bellow

return imagesx($img_src);

}

return 0;

}

function getImageHeight($filename){

if(file_exists($filename))

{

$ext = getExtension($filename);

if(!$ext)

return 0;

$img_src = getImageResource($ext, $filename);

return imagesy($img_src);

}

return 0;

}

To get the image Extension here is the function

function getExtension($filename)//the filename is path of the image

{

if($filename == '')

return false;

$ext = substr( $filename, strrpos( $filename, "." )+1 );

return $ext;

}

To get the image resource to get the image width or height

So the following function gives you the resource of the image type

function getImageResource($ext, $filename)//the image extension and the image path should be given

{

$imageresource = '';

if($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG"){

$imageresource = imagecreatefromjpeg($filename);

}

if($ext == "gif" || $ext == "GIF"){

$imageresource = imagecreatefromgif($filename);

}

if($ext == "bmp" || $ext == "BMP"){

$imageresource = imagecreatefromwbmp($filename);

}

if($ext == "png" || $ext == "PNG"){

$imageresource = imagecreatefrompng($filename);

}

/*if(!$imageresource){//if not valid image

return false;

}*/

return $imageresource;

}

And finally how to create image file by using the extension , image resource and destination filename. The following function create image file with this parameters

Parameter list for the function

//here $ext is extension of the image

//$imgresource is the resource of the image with the width and height this you can get by $dst_im = imagecreatetruecolor($width, $height);

//$dest_filename is the destination file name where you want to save the file

function createImagefile ($ext, $imgresource, $dest_filename)

{

$imgfile = false;

if($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG"){

$imgfile = imagejpeg($imgresource, $dest_filename);

}

if($ext == "gif" || $ext == "GIF"){

$imgfile = imagegif($imgresource, $dest_filename);

}

if($ext == "png" || $ext == "PNG"){

$imgfile = imagepng($imgresource, $dest_filename);

}

if($ext == "bmp" || $ext == "BMP"){

$imgfile = imagewbmp($imgresource, $dest_filename);

}

/*if($imgfile)

return true;*/

return $imgfile;

}

Have any Bug Please contact me

Friday, July 10, 2009

How to call stored procedure in MDB2 php abstraction package

How to call stored procedure in MDB2 php abstraction package

you may be facing difficult in calling stored procedure in your MDB2 database package

here is a solution to over come the difficulty

in this process first create the db connection in your file and get the object of that connection the following code shows how to connect your db

require_once 'MDB2.php';

$con = MDB2::connect('pgsql://usr:pw@localhost/dbnam');
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}

assuming you have your db connected object in $con

and create function where you can execute your query string separately like shown below “doquery” function

function doquery()

{

if(empty($con))

$con = $dao->Connect();

$resultset = $con->query($sql);

if(PEAR::isError($resultset)) {

die("Dao::doQuery() ::: Error while executing query: " . $sql . "
Error Message:" . $resultset->getMessage());

}

$object = Array();

while($row = $resultset->fetchRow()) {

$object[] = $row;

}

return $object;

}

Then in next step you can have call to the stored procedure in your php file where you want to call your stored procedure

The below code shows you how to call

$query = "CALL storedproceduer_name($parameter1,$parameter2,….);";

$result_value = Dao::doQuery($query);

This $result_value will gives you the result set of stored procedure

And you can test this by

Print_r($result_value);

How to call Transaction in MDB2 php abstraction package

How to call Transaction in MDB2 php abstraction package

Method 1

If your using MDB2 database package and you want to run transaction in your page here is solution

You may be facing difficult in calling Transaction in your MDB2 database package

Here is a solution to over come the difficulty

To call transaction in your php file first you should create db connection object as you do in like in your MDB2 connection

The following code shows how to connect your db

require_once 'MDB2.php';

$con = MDB2::connect('pgsql://usr:pw@localhost/dbnam');
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}

Assuming you have your db connected object in variable $con

The following procedure will help you in calling transaction

Before start weather its support are not

// check if transaction are supported by this driver
if (!$con->supports('transactions')) {
exit();
}

//to start the transaction in your page use following code

$con->query("BEGIN");//to d=start the transaction

//execute your queries here

If(check query condition)//if its works fine

{

$con->query("COMMIT");");//Complete transaction

}

Else

{

$con->query("ROLLBACK");");//Transaction is not complete rollback your query

}

If you fina any difficulties in execution here is one more method which you can use

Method 2

// Open a transaction
$res = $mdb2->beginTransaction();

..

// check if we are inside a transaction and if savepoints are supported
if ($mdb2->inTransaction() && $mdb2->supports('savepoints')) {
// Set a savepoint
$savepoint = 'MYSAVEPOINT';
$res = $mdb2->beginTransaction($savepoint);

..

// determine if the savepoint should be released or to rollback to the savepoint
if ($error_condition) {
$res = $mdb2->rollback($savepoint);
} else {
$res = $mdb2->commit($savepoint);
}

How to find browser in PHP

How to find browser in PHP

This function gives you browser which the user currently using ….

Call this function with out parameter inside your php and assign this to any variable to get the browser which your using

//$variable_name = get_user_browser();

//echo “the browser you are using is=”.$variable_name;

The out is “the browser you are using is= firefox //if your are working in firefox

You can change the echo state in function according to your need

function get_user_browser()

{

$u_agent = $_SERVER['HTTP_USER_AGENT'];

$ub = '';

if(preg_match('/MSIE/i',$u_agent))

{

$ub = "ie";

}

elseif(preg_match('/Firefox/i',$u_agent))

{

$ub = "firefox";

}

elseif(preg_match('/Safari/i',$u_agent))

{

$ub = "safari";

}

elseif(preg_match('/Chrome/i',$u_agent))

{

$ub = "chrome";

}

elseif(preg_match('/Flock/i',$u_agent))

{

$ub = "flock";

}

elseif(preg_match('/Opera/i',$u_agent))

{

$ub = "opera";

}

return $ub;

}

How to get week number for year, start date and end date for week

How to get week number for year, start date and end date for week based on date given or present date in php…..
The following function gives you the number of week in year based on the date given the date format is mm/dd/yyyy if your date format is in yyyy/mm/dd here is conversion of date in the required format or you can jump that conversion
The function gives you the following list
-number of week in year
- week date for particular week u selected
-week days for the week
-start date for a week
-end date for a week
-next week start date
-previous week end date
get_week('2010-01-31');//pass the date in the formate
function get_week($date)

{
    $main_date=explode("-",$date);
    $week_date = $main_date[1]."/".$main_date[2]."/".$main_date[0];

    $ts = strtotime($week_date);
    $year = date('Y', $ts);
    $week = date('W', $ts);
    // print week for the current date
    for($i=1; $i<=7; $i++)
    {
    // timestamp from ISO week date format
    $ts = strtotime($year.'W'.$week.$i);
    $week_dates[$i] = date("Y-m-d", $ts);
    $Week_days[$i] = date("l",$ts);  
    }
    //to get the week strat date and previous week last date
    $mon=explode("-" ,$week_dates[1]);
    $start_prev = date ("Y-m-d", mktime (0,0,0,date($mon[1]),(date($mon[2])),date($mon[0])));

    //to get the end date of the week next week start date
  
    $sun=explode("-", $week_dates[7]);
  
    $end_next = date ("Y-m-d", mktime (0,0,0,date($sun[1]),(date($sun[2])),date($sun[0])));
    echo $start_prev ."---".$end_next;
    //return array($start_prev ,$end_next);

}
?>