Category: PHP

  • How to pass data from one domain to another domain(cross domain) using json?‏

    //Javascript code <script type=”text/javascript”> $(document).ready(function() { var surl =  “http://www.example.com/json.php”; email_id=document.getElementById(“email”).value; $.ajax({ url: surl, data: {email:email_id}, dataType: “jsonp”, jsonp : “callback”, jsonpCallback: “jsonpcallback” }); }); function jsonpcallback(rtndata) { document.getElementById(“disp_data”).innerHTML=rtndata.message; } </script> //json.php file code <?php $display=”<b>HI Json</b>”; $display.=”<p>HI This is testing json.</p>”; $rtnjsonobj->message = $display; echo $_GET[‘callback’]. ‘(‘. json_encode($rtnjsonobj) . ‘)’; ?>

  • error page using htaccess file

    first create .htaccess  file and save it. then write below code ErrorDocument 404 /404.html   here 404 means when page not found then it occurs 404.html means that page which you want to display.    

  • how to make captcha in php?

    Captcha Code: <?php session_start(); $num=”; $string = “abcdefghijklmnopqrstuvwxyz0123456789”; for($i=0;$i<7;$i++){ $num1=rand(0,35); $num .= $string{$num1}; } $_SESSION[“num1”]=$num; $img=imagecreatefrompng(‘captcha.png’); $color=imagecolorallocate($img,255,255,255); $color1=imagecolorallocate($img,0,0,0); imagestring($img,9,10,3,$num,30); $fontsize=20; $fontcolor = imagecolorallocate($img, 0, 0, 0); $x = 0; $y = $fontsize; header(‘Content-type : image/png’); imagepng($img); imagedestroy($img); ?> How to use in php? <img id=”cap” style=”margin-left: 15px;” src=”comman/captcha.php” alt=”” /> How to refresh captcha? Call…

  • how to check path of ffmpeg or mencoder in linux in php?

    <?php $output = shell_exec(‘whereis ffmpeg’); echo “<pre>”.$output.”</pre>”; echo “”; $output = shell_exec(‘whereis mencoder’); echo “<pre>”.$output.”</pre>”; echo “”; ?> Output in browser :

  • how to backup mysql database using php?

    <?php $backfile=”a.sql”; $command=”mysqldump  -u root test>$backfile”;// system($command); ?>

  • PHP mail with attachment

    <?php //Set Email Subject $subject = $_POST[‘sub’]; $message_email=$_POST[‘message’]; $message_email.='<br><br><br>’.$data; //define the from \ reply to headers $headers = “From: darshakkumarshah@mkics.in\r\nReply-To: darshakkumarshah@mkics.in”; //create a unique boundary string to delimit different parts of the email (plain text, html, file attachment) $random_hash = md5(date(‘r’, time())); //add boundary string and mime type specification $headers .= “\r\nContent-Type: multipart/mixed; boundary=\”PHP-mixed-“.$random_hash.”\””; //read…

  • Display data dynamically in Matrix format using PHP with pagination

    <?php $per_page = 6; $display_columns = 3; $page = isset($_GET[‘page’]) ? (int) $_GET[‘page’] : 1; $pages = implode(mysql_fetch_assoc(mysql_query(“SELECT COUNT(*) FROM projects”))); //$pages= $pages/$display_columns; $pages = ceil($pages / $per_page); $querystring = “”; foreach ($_GET as $key => $value) { if ($key != “page”) $querystring .= “$key=$value&amp;”; } echo “Pages: “; for ($i = 1; $i <=…

  • PHP: Mail with HTML and mail() function.

    <?php include (“include/config.php”); $fname=$_POST[‘name’]; $email=”From:”.$_POST[’email’]; $comp=$_POST[‘company’]; $msg1=$_POST[‘message’]; $tomail=”swapn_developers@yahoo.com”; $msg=”Company Name : ” .$comp.” “.”Message : ” .$msg1; $headers = “From: $email\r\n”; $headers .= “Content-type: text/html\r\n”; mail($tomail,”Contact Us Message”,$msg,$headers); ?>

  • How to Download Image , txt file or any file without save as or without open in php?

    <?php $file=$_GET[‘file’];//get the file name //$file = ‘monkey.gif’; if (file_exists($file)) { header(‘Content-Description: File Transfer’); header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=’.basename($file)); header(‘Content-Transfer-Encoding: binary’); header(‘Expires: 0’); header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’); header(‘Pragma: public’); header(‘Content-Length: ‘ . filesize($file)); ob_clean(); flush(); readfile($file); exit; } ?>

  • bb-press customize login module

    if ( !function_exists(‘bb_check_login’) ) : function bb_check_login($user, $pass, $already_md5 = false) { global $wp_users_object; if ( !bb_get_option( ’email_login’ ) || false === strpos( $user, ‘@’ ) ) { // user_login $user = $wp_users_object->get_user( $user, array( ‘by’ => ‘login’ ) ); } else { // maybe an email echo $email_user = $wp_users_object->get_user( $user, array( ‘by’ =>…