Tuesday, August 31, 2010

Javascript function to check Password Strength

There is few line of code for check strength at client side with the help of Javascript and CSS.

In this code JS function will check the combination of password by found simple character and numeric character and special character.  and Check length of password it should be more or equal of 6.

Password with simple only character or number will week and with combination of character and number will medium and with character and number and special character is strong.

Css Code 
.strength0
{
width:250px;
background:#cccccc;
}

.strength1
{
width:50px;
background:#ff0000;
}

.strength2
{
width:100px;
background:#ff5f5f;
}

.strength3
{
width:150px;
background:#56e500;
}

.strength4
{
background:#4dcd00;
width:200px;
}

.strength5
{
background:#399800;
width:250px;
}

Javascript Function Code

function passwordStrength(password,passwordStrength,errorField)
{
var desc = new Array();
desc[0] = "Very Weak";
desc[1] = "Weak";
desc[2] = "Better";
desc[3] = "Medium";
desc[4] = "Strong";
desc[5] = "Strongest";

var score   = 0;

//if password bigger than 6 give 1 point
if (password.length > 6) score++;

//if password has both lower and uppercase characters give 1 point
if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

//if password has at least one number give 1 point
if (password.match(/\d+/)) score++;

//if password has at least one special caracther give 1 point
if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;

//if password bigger than 12 give another 1 point
if (password.length > 12) score++;

passwordStrength.innerHTML = desc[score];
passwordStrength.className = "strength" + score;
}



Html Code of Use it



<input id="password" name="password" onblur="passwordStrength(this.value,document.getElementById('strendth'),document.getElementById('passError'))" size="40" type="password" value="&lt;?=$getRs[0]['contact_person_name']?&gt;" />
<span id="passError"></span><span id="strendth"></span>

Working Output 


For Very weak and weak


pass:- abcdef or abcdef123


for better pass:-abcdef12345


for strong 



Wednesday, August 4, 2010

Dynamic Pagination by Selecting Page No

Pagination by selecting page no for navigation,


This code will help u send page no as parameter in url for navigate in paging.

we send page no 1,2,3 not sending record start position for record show or navigate.




//paging style css code start


.paging { padding:10px 0px 0px 0px; text-align:center; font-size:13px;}
  .paging.display{text-align:right;}
  .paging a, .paging span {padding:2px 8px 2px 8px;}
  .paging span {font-weight:bold; color:#000; font-size:13px; }
  .paging a {color:#000; text-decoration:none; border:1px solid #dddddd;}
  .paging a:hover { text-decoration:none; background-color:#6C6C6C; color:#fff; border-color:#000;}
  .paging span.prn { font-size:13px; font-weight:normal; color:#aaa; }
  .paging a.prn { border:2px solid #dddddd;}
  .paging a.prn:hover { border-color:#000;}
  .paging p#total_count{color:#aaa; font-size:12px; padding-top:8px; padding-left:18px;}
  .paging p#total_display{color:#aaa; font-size:12px; padding-top:10px;}



//paging style css code end


 


 


// paging php code start


$num; //total no of record from sql query


$display;//no of record display on page


$noDisplayPageNo=10; // no of page no range want to show on page


$query=""; // addition parameter or sending data need to send with page no in url


$display=10;
if(!isset($_REQUEST['init']) || $_REQUEST['init']==""){
$init=$start=0;

}else{
$init=$_REQUEST['init'];
$start=($init)*$display;
}


$pages=ceil($num/$display);

$current = ($start/$display)+1;

$startpageNo=max($current-intval($noDisplayPageNo/2), 1); // start page no range
$endpageNo=$start+$noDisplayPageNo-1; // end page no range



if(strlen($query)>0){
$query = "&amp;".$query_string;
}


echo '<div class="paging">';

if($current==1) {
echo '<span class="prn">&lt; Previous</span> ';
} else {
$i = $current-1;
//echo '--'.$i;
echo '<a class="prn" title="go to page '.$i.'" rel="nofollow" href="'.$_SERVER['PHP_SELF'].'?init='.($i-1).$query.'">&lt; Previous</a>';
echo '<span class="prn">...</span> ';
}



for ($i = $startpageNo; $i <= $endpageNo && $i <= $pages; $i++){
if($i==$current) {
echo '<span>'.$i.'</span> ';
} else {
echo '<a title="go to page '.$i.'" href="'.$_SERVER['PHP_SELF'].'?init='.($i-1).$query.'">'.$i.'</a> ';
}
}


if($current < $pages) {
$i = $current;
echo '<span class="prn">...</span> ';
echo '<a class="prn" title="go to page '.$i.'" rel="nofollow" href="'.$_SERVER['PHP_SELF'].'?init='.$i.$query.'">Next &gt;</a> ';
} else {
echo '<span class="prn">Next &gt;</span> ';
}


if ($total != 0){
//prints the total result count just below the paging
echo '(total '.$pages.' results)</div>';
}

Friday, May 28, 2010

Integrate Firebug Lite with all browser

Integrate Firebug lite with all available browser like Crome,Safari,IE

firebug is most advance tool for correct or check web page design like css,html tags.

It hard to install firebug to all browser. only mozilla firefox support the installation of firebug.

For using firebug in browser just copy below code and past it to before &lt/body &gt tag. So firebug lite link will appear on click firebug will work for that page on which that code present.

<a href="javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E=F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','1.3.0.3','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');">Firebug Lite</a>

Wednesday, May 5, 2010

Php Script for Check Email open

How to check that send email is open by receiver or not

If we send email use Php mail() function and want that you get information when receiver open that mail or want to keep record of open mail send in mass sending of mail using Php mail() function. To do that we use following code.




$to=""; //email receiver id
$subj=""; // subject of mail
$msg=""; // message that send to receiver
$senderheaders  = "From: news@example.com\r\n";
$senderheaders .= "Content-type: text/html\r\n";
$senderheaders.="<img src=\"http://www.example.com/trackemail.php?receiverId=$id\" width=\"1\" height=\"1\" />";

mail($to,$subj,$msg,$senderheaders);
?>

In above code we send image of 1*1px with the header of the mail. when receiver open that mail that will send back to tracking file of sender site and tell them that email is check by receiver.




Monday, May 3, 2010

Integration of CCAVENUE Payment gateway

Integration of CCAVENUE Payment Cart in Your Shopping Section 


CCavenue is most popular Payment gateway for online Shopping. It provide payment through using International credit card as well using your Bank (who have bond with CCavenue) online Account or using it's debit card(ATM card). It is one of the most secure place for given your money to online shop.

For Integrate it with your website you should have ccavenue account and they give you a merchant id and a unique key for your site that is most important for money transaction.


Php Function's Require TO Validate Require Value for CCAvenue Payment.


<?php


function getchecksum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
  {
  $str ="$MerchantId|$OrderId|$Amount|$URL|$WorkingKey";
  $adler = 1;
  $adler = adler32($adler,$str);
  return $adler;
  }


function verifychecksum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey)
  {
  $str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
  $adler = 1;
  $adler = adler32($adler,$str);

  if($adler == $CheckSum)
  return "true" ;
  else
  return "false" ;
  }


function adler32($adler , $str)
  {
  $BASE =  65521 ;


$s1 = $adler & 0xffff ;
  $s2 = ($adler >> 16) & 0xffff;
  for($i = 0 ; $i < strlen($str) ; $i++)
  {
  $s1 = ($s1 + Ord($str[$i])) % $BASE ;
  $s2 = ($s2 + $s1) % $BASE ;
  //echo "s1 : $s1 <BR> s2 : $s2 <BR>";


}
  return leftshift($s2 , 16) + $s1;
  }


function leftshift($str , $num)
  {


$str = DecBin($str);


for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
  $str = "0".$str ;


for($i = 0 ; $i < $num ; $i++)
  {
  $str = $str."0";
  $str = substr($str , 1 ) ;
  //echo "str : $str <BR>";
  }
  return cdec($str) ;
  }


function cdec($num)
  {


for ($n = 0 ; $n < strlen($num) ; $n++)
  {
  $temp = $num[$n] ;
  $dec =  $dec + $temp*pow(2 , strlen($num) - $n - 1);
  }


return $dec;
  }
  ?>







CCAvenue Passing Parameter That Require for Complete the Shopping


<?php
    $Merchant_Id = "";//This id(also User Id)  available at "Generate Working Key" of "Settings & Options"
    $Amount = $orderdata[5];//your script should substitute the amount in the quotes provided here
    $Order_Id = $orderdata[0];;//your script should substitute the order description in the quotes provided here
    $WorkingKey = "";//Given to merchant by ccavenue
    $Redirect_Url ="http://www.example.com/shopping.php";
    $Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id ,$Redirect_Url,$WorkingKey); // Validate All value
    ?>
<p align="center" style="font-family:Calibri; font-size:18px;"><img src="http://www.example.com/images/loader.gif" alt="loader"></p>
<p align="center" style="font-family:Calibri; font-size:24px;color:#3670A7;">Processing to CCAvenue..............</p>
<form id="form2" method="post" action="https://www.ccavenue.com/shopzone/cc_details.jsp">
<input type=hidden name=Merchant_Id value="<?php echo $Merchant_Id; ?>">
<input type="hidden" name="Amount" value="<?php echo $Amount; ?>">
<input type="hidden" name="Order_Id" value="<?php echo $Order_Id; ?>">
<input type="hidden" name="Redirect_Url" value="<?php echo $Redirect_Url; ?>">
<input type="hidden" name="Checksum" value="<?php echo $Checksum; ?>">
<input type="hidden" name="billing_cust_name" value="<?= $orderdata[7].' '.$orderdata[8];?>"> <!--Pass Customer Full Name -->
<input type="hidden" name="billing_cust_address" value="<?= $orderdata[9].' '.$orderdata[10];?>"><!--Pass Customer Full Address-->
<input type="hidden" name="billing_cust_country" value="<?= $orderdata[15];?>"> <!--Pass Customer Country -->
<input type="hidden" name="billing_cust_state" value="<?= $orderdata[14];?>"><!--Pass Customer State -->
<input type="hidden" name="billing_cust_city" value="<?= $orderdata[13];?>"> <!--Pass Customer City -->
<input type="hidden" name="billing_zip" value="<?= $orderdata[16];?>"> <!--Pass Customer Zip Code-->
<input type="hidden" name="billing_cust_tel" value="<?= $orderdata[11];?>"> <!--Pass Customer Phone No-->
<input type="hidden" name="billing_cust_email" value="<?= $orderdata[12];?>"> <!--Pass Customer Email address-->
<input type="hidden" name="delivery_cust_name" value="<?= $orderdata[7].' '.$orderdata[8];?>"> <!--Pass Same or other other detail fill by customer-->
<input type="hidden" name="delivery_cust_address" value="<?= $orderdata[9].' '.$orderdata[10];?>">
<input type="hidden" name="delivery_cust_country" value="<?= $orderdata[15];?>">
<input type="hidden" name="delivery_cust_state" value="<?= $orderdata[14];?>">
<input type="hidden" name="delivery_cust_tel" value="<?= $orderdata[11];?>">
<input type="hidden" name="delivery_cust_notes" value="">
<input type="hidden" name="Merchant_Param" value="">
<input type="hidden" name="billing_zip_code" value="<?= $orderdata[16];?>">
<input type="hidden" name="delivery_cust_city" value="<?= $orderdata[13];?>">
<input type="hidden" name="delivery_zip_code" value="<?= $orderdata[16];?>">


</form>



Friday, April 30, 2010

Paypal Webstie Standard Payment Method

Paypal Webstie Standard Payment Method for website

    
When we use Paypal website standard payment method for shopping cart with multiple buy item. On this method customer complete it's shopping on website and the time of payment he completely move to paypal website with complete detail of his buy item name, item qty , item amount and with Total Amount. On paypal site all detail will display as display on his shopping cart. here all necessary field that is will on site like first name, address,etc. will automatically filled and here customer need to just fill their credit card and it’s related field’s to complete the process.    

    
When customer complete the payment process then one url of success payment is also send form the site to paypal (in return input type) site will appear in form button on click on that button customer will reach to success page of website.      

    
There is on link of fail on cancel for not to complete the process.

    






Paypal Require Code:-





<form id="form1" action="https://www.paypal.com/cgi-bin/webscr" method="post">
  <input type="hidden" name="business" value="{$merchantId}" />


<!--merchant paypal id in which payment will go-->
  <input type="hidden" name="cmd" value="_cart" />
  <input type="hidden" name="paymentaction" value="sale" />
  <?php

 // $itemresult result set of customer buy item fetch form order_item table and table where final order item is store
 $i=1;
 while($row = mysql_fetch_array($itemresult))
 {
 $amountinrupee = $row[1];
 $amount = round(intval($amountinrupee)/46.180,2);

 ?>
  <input type="hidden" name="item_name_<?= $i;?>" value="<?= $row[0];?>" />
  <input type="hidden" name="amount_<?= $i;?>" value="<?= $amount;?>" />
  <input type="hidden" name="quantity_<?= $i;?>" value="<?= $row[2];?>" />
  <?php
 $i++;
 }
 ?>
  <input type="hidden" name="first_name" value="<?= $orderdata[7];?>" /><!--customer first name -->
  <input type="hidden" name="last_name" value="<?= $orderdata[8];?>" /><!--customer last name -->
  <input type="hidden" name="address1" value="<?= $orderdata[9];?>" /><!--customer address 1 name -->
  <input type="hidden" name="address2" value="<?= $orderdata[10];?>" /><!--customer add2 name -->
  <input type="hidden" name="email" value="<?= $orderdata[12];?>" /><!--customer email name -->
  <input type="hidden" name="city" value="<?= $orderdata[13];?>" /><!--customer city name -->
  <input type="hidden" name="state" value="<?= $orderdata[14];?>" /><!--customer state name -->
  <input type="hidden" name="country" value="<?= $orderdata[15];?>" /><!--customer country name -->
  <input type="hidden" name="zip" value="<?= $orderdata[16];?>" /><!--customer zip name -->
  <input type="hidden" name="currency_code" value="USD" /><!--currrecy in which payment u need-->
  <input type="hidden" name="upload" value="1" /><!--paypal parameter-->
  <input type="hidden" name="return" value="http://www.example.com/shopcomplete.php" />
  <input type="hidden" name="cancel_return" value="http://www.example.com/shopfail.php" />
  </form>



Thursday, April 29, 2010

Integrate Phpbb3 forum login(session) with website

Integrate Phpbb3 forum login(session) with website
When we use third part tool phpbb3 with your website as site forum there is necessary  to set phpbb3 login session when any user login to website so user can also use forum without re-login to phpbb3 forum because there is many session variable that is require for login to forum and work on it.
Example:-
Website name:-www.example.com
Website forum:- www.example.com/forum/
Website login page:-www.example.com/login.php
There is 3 way to reach to site forum first open/land to index.php page and reach to it’s viewforum.php page and reach to it’s viewtopic.php page
Website forum page use by user:-
www.example.com/forum/index.php,
First we need that user that is register with site also have entry in phpbb3 forum users table and user_group with same user id that is given on site registration time.
When we move site to forum any above forum page than we need to pass that user id as parameter and get that parameter then fetch record from site user table and set all necessary session parameter for keep login on form.



 Forum login session set code:-


//get site user Id
$var_id=$_GET['id'];
//start forum user session
$user->session_begin();
//check user id exist or login 
if($var_id!='')
{
$str="select * from site_members where member_id=$var_id"; 
$qstr=mysql_query($str,$dbc) or die('error in members'.mysql_error());
$fstr=mysql_fetch_array($qstr);
    
   $user->data[user_ip] = $_SERVER['REMOTE_ADDR'];
    $user->data[user_regdate] = 0;
    $user->data[username] = $fstr['first_name'];
    $user->data[username_clean] = $fstr['first_name'];
    $user->data[user_password] = md5($fstr['password']);
    $user->data[user_passchg] = 0;
    $user->data[user_pass_convert] = 0;
    $user->data[user_email] = '';
    $user->data[user_email_hash] = 0;
    $user->data[user_birthday] =  0- 0-   0;
    $user->data[user_lastvisit] = 1238142551;
    $user->data[user_lastmark] = 0;
    $user->data[user_lastpost_time] = 0;
    $user->data[user_lastpage] = index.php;
    $user->data[user_last_confirm_key] = '';
    $user->data[user_last_search] = 0;
    $user->data[user_warnings] = 0;
    $user->data[user_last_warning] = 0;
    $user->data[user_login_attempts] = 0;
    $user->data[user_inactive_reason] = 0;
    $user->data[user_inactive_time] = 0;
    $user->data[user_posts] = 1;
    $user->data[user_lang] = en;
    $user->data[user_timezone] = 0.00;
    $user->data[user_dst] = 0;
    $user->data[user_dateformat] = 'd M Y H:i';
    $user->data[user_style] = 1;
    $user->data[user_rank] = 0;
    $user->data[user_colour] = '';
    $user->data[user_new_privmsg] = 0;
    $user->data[user_unread_privmsg] = 0;
    $user->data[user_last_privmsg] = 0;
    $user->data[user_message_rules] = 0;
    $user->data[user_full_folder] = -3;
    $user->data[user_emailtime] = 0;
    $user->data[user_topic_show_days] = 0;
    $user->data[user_topic_sortby_type] = t;
    $user->data[user_topic_sortby_dir] = d;
    $user->data[user_post_show_days] = 0;
    $user->data[user_post_sortby_type] = t;
    $user->data[user_post_sortby_dir] = a;
    $user->data[user_notify] = 1;
    $user->data[user_notify_pm] = 0;
    $user->data[user_notify_type] = 0;
    $user->data[user_allow_pm] = 1;
    $user->data[user_allow_viewonline] = 1;
    $user->data[user_allow_viewemail] = 0;
    $user->data[user_allow_massemail] = 1;
    $user->data[user_options] = 831;
    $user->data[user_avatar] = '';
    $user->data[user_avatar_type] = 0;
    $user->data[user_avatar_width] = 0;
    $user->data[user_avatar_height] = 0;
    $user->data[user_sig] = '';
    $user->data[user_sig_bbcode_uid] = '3m872xlu';
    $user->data[user_sig_bbcode_bitfield] = 0;
    $user->data[user_from] = '';
    $user->data[user_icq] = '';
    $user->data[user_aim] = '';
    $user->data[user_yim] = '';
    $user->data[user_msnm] = '';
    $user->data[user_jabber] = '';
    $user->data[user_website] = '';
    $user->data[user_occ] = '';
    $user->data[user_interests] = '';
    $user->data[user_actkey] = '';
    $user->data[user_newpasswd] = '';
    $user->data[user_form_salt] = '168ff8093150140f';
    $user->data[session_id] = session_id();
    $user->data[session_user_id] = $fstr["member_id"];;
    $user->data[session_forum_id] = 0;
    $user->data[session_last_visit] = '1238142551';
    $user->data[session_start] = time();
    $user->data[session_time] = time();
    $user->data[session_ip] = $_SERVER['REMOTE_ADDR'];
    $user->data[session_browser] = $_SERVER['HTTP_USER_AGENT'];
    $user->data[session_forwarded_for] = '';
    $user->data[session_page] = 'index.php';  
    $user->data[session_viewonline] = 1;
    $user->data[session_autologin] = 0;
    $user->data[session_admin] = 0;
    $user->data[is_registered] = 1;
    $user->data[is_bot] = '';
    $autologin='true';
    $result = $auth->login($fstr['username'], $fstr['password'], $autologin);
    $result['error_msg']=LOGIN_SUCCESS;
}




Note-

1.    $user->data[session_page] = 'index.php';  

index.php is the value according to page on which it is use like for viewforum.php it will be viewforum.php and for viewtopic.php it will be viewtopic.php

2.
$auth->login($username, $password, $remember, 1, 0)


$username would be the exact username that would be found in the phpBB user table.

$password would be the string to match by (pre-hash, this should be just the original text, the $auth->login() function takes care of converting it into a comparable hash)

$remember is a boolean value, false if no remember me choice, true if user is going to have a 'remembered' session