Thursday, 20 March 2014

Add Ckeditor from online

<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>
<textarea id="editor1" name="Content1" class="" rows="10" cols="50" style="width: 80%">

Thursday, 14 November 2013

Every 3 second change the image with database

Do connection with database itself then do.........
Table name >> cms_banner_master with this fields id,imagenm,onclick_url


//http://websitename/
//uploadfiles Stored images

$imageDir = '/websitename/uploadfiles/';
define('SERVERPATH', $_SERVER['DOCUMENT_ROOT'].$imageDir);
define('HTTPPATH', 'http://'.$_SERVER['HTTP_HOST'].$imageDir);


$array=array();
$linkarray=array();
$query=getdata("select imagenm,onclick_url from  cms_banner_master" );
while($rs=mysql_fetch_array($query))
{
$image=$rs['imagenm'];
$link=$rs['onclick_url'];
$array[]=$rs['imagenm'];
$linkarray[]=$rs['onclick_url'];
}

$dir = opendir(SERVERPATH);
$javascriptArray = null;
$JLINK=null;
$i = null;


foreach($array as $imagevalue)
{
   if (eregi('\.(gif|png|jpg)$',$imagevalue)){
 $javascriptArray .= $i.'"'.HTTPPATH.$imagevalue.'"';
       $i = ',';
    }
}
foreach($linkarray as $linkvalue)
{
$JLINK.=$linkvalue.',';
}
$JLINK=substr($JLINK, 0, -1);

closedir($dir);

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        <title>Rotate Images</title>

<script type="text/javascript">
         function rotateImage(){
var linkImages='<?php echo $JLINK;?>'.split(',');
   rotatingImages = new Array(<?php echo $javascriptArray; ?>);
            imageCount = rotatingImages.length;

            firstTime = true;
            duration = "3"; //seconds
                // Cycle through images sequencially starting with a random image
                // Do not update the image if loading is not yet completed
                if (document.getElementById('rotatingImage').complete || firstTime){
                    if (firstTime) {
                        thisImage = Math.floor((Math.random() * imageCount))
                        firstTime = false
                    }else{
                        thisImage++
                        if (thisImage == imageCount) {
                            thisImage = 0
                        }

                    }
document.getElementById('rotatingImage').src = rotatingImages[thisImage]
for (var k=0;k<linkImages.length;k++)
{
 var a=document.getElementById('href').href=linkImages[thisImage];
}
setTimeout("rotateImage()", duration * 1000)
                }

            }
        </script>


 </head>
    <body>
        <div id="slideshow">
<a id="href" target="_blank"><img  height="186" width="308"   id="rotatingImage"  alt="" /></a>
        </div>
        <script type="text/javascript">
            rotateImage();
        </script>
    </body>
</html>




Every 3 Second change image From Directory

<?php
// PHP section

// set some variables
// Image directory! fill in! relative to root

//http://localhost/time/
//slides  stored images

$imageDir = '/time/slides/'; 
define('SERVERPATH', $_SERVER['DOCUMENT_ROOT'].$imageDir);
define('HTTPPATH', 'http://'.$_SERVER['HTTP_HOST'].$imageDir);
// read the names of images from the image directory

$files=array('1.jpg','2.jpg');

$dir = opendir(SERVERPATH);
$javascriptArray = null;
$i = null;
foreach($files as $imagevalue)
{
   if (eregi('\.(gif|png|jpg)$',$imagevalue)){
  $javascriptArray .= $i.'"'.HTTPPATH.$imagevalue.'"'; 
       $i = ',';
    }
}

closedir($dir);

// Html section
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        <title>Rotate Images</title>
        <script type="text/javascript">
            rotatingImages = new Array(<?php echo $javascriptArray; ?>);
            imageCount = rotatingImages.length;
            firstTime = true;
            duration = "3"; //seconds
        
            function rotateImage(){
                // Cycle through images sequencially starting with a random image
                // Do not update the image if loading is not yet completed
                if (document.getElementById('rotatingImage').complete || firstTime){
                    if (firstTime) {
                        thisImage = Math.floor((Math.random() * imageCount))
                        firstTime = false
                    }else{
                        thisImage++
                        if (thisImage == imageCount) {
                            thisImage = 0
                        }
                    }
                    document.getElementById('rotatingImage').src = rotatingImages[thisImage]
                    setTimeout("rotateImage()", duration * 3000)
                }
            }
        </script>
      
    </head>
    <body>
        <div id="slideshow">
            <img id="rotatingImage" src="" alt="" height="200" width="200">
        </div>
        <script type="text/javascript">
            rotateImage();
        </script>
    </body>
</html>

Sunday, 15 September 2013

How to store array in mysql?

How to store array in mysql?

This is one of the mostly asked question by php programmer because mysql doesn't has any array data type. So we can not store array directly into mysql database.
To do this we have to first convert array into string using php serialize() function then save it into mysql database.

php code to store array in database

1
2
3
4
5
6
7
<?
$array = array("foo", "bar", "hello", "world");
$conn=mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_select_db("mysql_db",$conn);
$array_string=mysql_escape_string(serialize($array));
mysql_query("insert into table (column) values($array_string)",$conn);
?>

To retrieve array from database

1
2
3
4
5
6
7
8
9
10
<?
$conn=mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_select_db("mysql_db",$conn);
$q=mysql_query("select column from table",$conn);
while($rs=mysql_fetch_assoc($q))
{
$array= unserialize($rs['column']);
print_r($array);
}
?>

Friday, 19 July 2013

PIN PAYMENT CREDIT CARD CODE

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://test-api.pin.net.au/1/charges");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_CERTINFO, true);

// downloaded from http://curl.haxx.se/docs/caextract.html
$crt = getcwd() . '/cacert.pem';

// specify CAINFO to allow HTTPS
curl_setopt($ch, CURLOPT_CAINFO, $crt);
curl_setopt($ch, CURLOPT_USERPWD, "YOUR_TEST_SECRET_API_KEY");

$fields = array(
  'amount' => '400',
  'description' => 'test charge',
  'email' => 'roland@pin.net.au',
  'ip_address' => '203.192.1.172',
  'card' => array(
    'number' => '5520000000000000',
    'expiry_month' => '05',
    'expiry_year' => '2013',
    'cvc' => '123',
    'name' => 'Roland Robot',
    'address_line1' => '42 Sevenoaks St',
    'address_city' => 'Lathlain',
    'address_postcode' => '6454',
    'address_state' => 'WA',
    'address_country' => 'AU'
  )
);


$postData = json_encode($fields);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

$response = curl_exec($ch); curl_close($ch);
$jsonResponse = json_decode($response, true);
$sucess = $jsonResponse["response"]["status_message"];

Extract website data using php like Crawling

function getHTML($url,$timeout)
{
       $ch = curl_init($url); // initialize curl with given url
       curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set  useragent
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
       curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
       return @curl_exec($ch);
}
function getHTML($url,$timeout)
{
       $ch = curl_init($url); // initialize curl with given url
       curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set  useragent
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
       curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
       return @curl_exec($ch);
}
$html=getHTML("http://www.website.com",10);
// Find all images on webpage
foreach($html->find("img") as $element)
echo $element->src . '<br>';
 
// Find all links on webpage
foreach($html->find("a") as $element)
echo $element->href . '<br>';


I hope this working