Sunday, 18 September 2011

function with static variables


static variables can not be reset
values can not change after execution
can not accessible through out the programme

function with global variables

accesible through program.
it generates a unique value after execution
can not assign any values at the time of declaring it or using it

php functions

means set of instructions
the basic syntax
function <function name>($arguments1, $arguments2, ......) {
 statements1;
 statements2;
}

It has four parts
-Special word function
-names that u want to give your function name
- function parameters list precided by dollar sign
- function body brace enclosed set of statements
Example

<?php

function xyz()
 {
 ----
-----
}
?>

php is HTML embeddedness

Php is embedded within HTML.
 All embeded scripting language don't need to be compiled into binary code before they can be tested or used , just write  and run.
but PHP is interpreted.

PHP is portable (Cross Platform  Compatible)

we can developed on any client OS and then uploaded your  php script to a server on any OS.
Not tag based

Wednesday, 14 September 2011

CCavenue PHP script - Free ccavenue developers code in php


<?php
$Merchant_Id = "your_merchantid";//This id(also User Id) available at "Generate Working Key" of "Settings & Options"
$Amount = "amount";//your script should substitute the amount in the quotes provided here
$Order_Id ="orderid";//your script should substitute the order description in the quotes provided here
$WorkingKey = "working_key";//Given to merchant by ccavenue
$Redirect_Url ="http://www.yoursite.com/ccavenue_returndata.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="yourname"> <!--Pass Customer Full Name -->
<input type="hidden" name="billing_cust_address" value="123 Green Acres,West Eden"><!--Pass Customer Full Address-->
<input type="hidden" name="billing_cust_country" value="India"> <!--Pass Customer Country -->
<input type="hidden" name="billing_cust_state" value="AP"><!--Pass Customer State -->
<input type="hidden" name="billing_cust_city" value="Kakinada"> <!--Pass Customer City -->
<input type="hidden" name="billing_zip" value="533002"> <!--Pass Customer Zip Code-->
<input type="hidden" name="billing_cust_tel" value="9999999999"> <!--Pass Customer Phone No-->
<input type="hidden" name="billing_cust_email" value="test_test@yahoo.com"> <!--Pass Customer Email address-->
<input type="hidden" name="delivery_cust_name" value="delivery_name"> <!--Pass Same or other other detail fill by customer-->
<input type="hidden" name="delivery_cust_address" value="123 Green Acres,West Eden">
<input type="hidden" name="delivery_cust_country" value="India">
<input type="hidden" name="delivery_cust_state" value="AP">
<input type="hidden" name="delivery_cust_tel" value="999999999">
<input type="hidden" name="delivery_cust_notes" value="Testing ccav">
<input type="hidden" name="Merchant_Param" value="">
<input type="hidden" name="billing_zip_code" value="533002">
<input type="hidden" name="delivery_cust_city" value="Kakinada">
<input type="hidden" name="delivery_zip_code" value="533002">
<input type="submit" value="Proceed to Buy Now" />
</form>
<?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;
}
?>

Monday, 5 September 2011

How to upload files int to server using Php?

You should make two pages in WebBuilder: the form page and the processing page. The latter holds the PHP script and will report all successful uploads.

I - The form page
1. Draw a Form Area and change the Form Properties to:
- Action: upload_plus.php
- Method: POST
- Encoding type: multipart/form-data

2. Make up your form. Remarks:
- include one or more File Upload objects and name all of them userfile[]
- include a Push Button and set the Button Type to Submit
- do not include any other form elements.

II - The processing page
1. Make up a nice page according the style of your site. Remarks:
- tell your visitors that the listed files are uploaded succesfully.
- include a link or menu to other pages of your site.

2. Rename the page to upload_plus using the Site Manager.
3. Bring up the Page Properties dialogue and change it to:
- File Extension: php

4. Draw an HTML object.
- The object size should be enough for the list of uploaded files.
- Bring up the HTML Properties dialogue and insert this:

Code:
<?php
$uploaddir = './uploads/';
$allowed = array('jpg','jpeg','gif','pdf');
$max_size = 1024 * 1024;
# No edits beyond this line

if (isset($_FILES['userfile'])) {
foreach ($_FILES['userfile']['error'] as $i => $error) {
if ($error == 0 && $_FILES['userfile']['size'][$i] <= $max_size) {
$file_ext = pathinfo($_FILES['userfile']['name'][$i],PATHINFO_EXTENSION);
$file_name = basename($_FILES['userfile']['name'][$i],'.'.$file_ext);
if (in_array(strtolower($file_ext),$allowed)) {
$new_base = $_FILES['userfile']['name'][$i];
$t = 1;
while (file_exists($uploaddir.$new_base)) {
$new_base = $file_name.'['.$t.'].'.$file_ext;
$t++;
}
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i],$uploaddir.$new_base)) {
chmod($uploaddir.$new_base, 0644);
echo 'Successful upload: '.$_FILES['userfile']['name'][$i].'<br>'."\n";
}
}
}
}
}
?>

III - Final steps
1. Publish your site.
2. Create an 'upload directory' named uploads on your server.
- This can be done using the FTP Manager or any other FTP client.
- Be sure this directory is on the same level as the processing page.
- Set the directory's permissions to: 777.

Wednesday, 31 August 2011

Print multi select option with comma in php

Using php we can print or display multiple select option with comma.
Copy this php code and test.
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>
<input name="submit" type="submit" value="Send" />
</form>
<?php
function comma($arr){
$length=count($arr);
if($length>=1)
{
$i=0;
foreach($arr as $key=>$value)
{
$i++ ;
if($i!=$length)
$itemid=$itemid.''.$value.', ';
if($i==$length)
$itemid=$itemid.''.$value;
}
}
return $itemid;
}
if(isset($_POST['submit'])){
if($_POST['test']!=''){
//sort($_POST['test']);
$country=comma($_POST['test']);
echo $country;
}
}
?>

Monday, 29 August 2011

php print statement

two basic contsructer for printing the outputs are echo and print. It prints only one arguments

code is:
print "Hello World";
or echo "Hello";
Related Posts Plugin for WordPress, Blogger...