Category Archives: Core Php

How to repeat the header on every page in mpdf ?

pdf_mpdf

If you want to add header in your custom mpdf and repeat the header for every page on mpdf then simply put the below code in your code and you can get the dynamic header in your generated pdf.

Step 1)

put the below code to your mpdf.

<htmlpageheader>
             {Header title}
</htmlpageheader>
<sethtmlpageheader name="MyHeader1" value="on" show-this-page="0" />

How to implement captcha in php?

captcha

This is the tutorial that can implement the captcha in the PHP form and verify the user which is a real user or any robot users. so just make the below files and set to your form which can attach the captcha.

Step 1)

Make php file and put the below code there.

<div>
     <img src="captcha_code.php"/>
     <input name="captcha_code" type="text" id="captcha_code" placeholder="Enter Captcha Code">
</div>

Step 2)

Make another file name “captcha_code.php”. put the below code in that file.

<?php
session_start();
$random_alpha = md5(rand());
$captcha_code = substr($random_alpha, 0, 6);
$_SESSION["captcha_code"] = $captcha_code;
$target_layer = imagecreatetruecolor(70,30);
$captcha_background = imagecolorallocate($target_layer, 148, 7, 10);
imagefill($target_layer,0,0,$captcha_background);
$captcha_text_color = imagecolorallocate($target_layer, 255, 255, 255);
imagestring($target_layer, 8, 8, 8, $captcha_code, $captcha_text_color);
header("Content-type: image/jpeg");
imagejpeg($target_layer);
?>

Step 3)

Now visit your form it will display the captcha code in your form.

HTTP Headers for ZIP File Downloads

maxresdefault

This tutorial will help you with generating zip files and directly download to your system. so just follow the step and you can get the zip file downloadable using the PHP code. this zip generates code will use of all system like mac, ubuntu, window and etc with a different browser.

Step 1)

copy below code in your PHP file.

<?php 

$filename = "Inferno.zip";
$filepath = "/var/www/domain/httpdocs/download/path/";

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
ob_end_flush();
@readfile($filepath.$filename);
ob_clean();
flush();
readfile($file);
ob_clean();
flush();
exit; 
?>

Step 2)

now run the url in your browser where you can direct download the zip file.

How to integrate PayPal in your PHP website?

paypal-logo

You are not aware of the PayPal payment gateway and you need to integrate PayPal in your PHP website then this tutorial will help you with how to integrate PayPal in the PHP website. No need to work with the hard code just simply follow the below steps and you can get the PayPal workable in your PHP website.

Step 1)

Click Here for download the PayPal standard code for PHP.

Step 2)

If you need to work with the live account then set the below URL in your form action

https://www.paypal.com

If you need to work with the sandbox account then set the below URL in your form action

https://www.sandbox.paypal.com/cgi-bin/webscr

Step 3)

Now you need to set your paypal email to the business input fields.

Also set the notify url, return url and cancel url of your website. where page will redirect after the action call.

Step 4)

When you follow the above steps successfully then you can get the paypal working in your php website.

Convert HTML to Ms Word Using Php Script

htmltomsword

In this tutorial, you can learn about how to convert text or export HTML to Microsoft Word File format by using PHP programming. If you develop any web application and in that application, you want to add one feature like you want to create Word Document from your PHP Web Application then at that time you can use this PHP Tutorial Script for Export HTML text to Microsoft Word. You can also format the word file from HTML code by putting a simple HTML tag and you can also use inline style sheet for change color, increase the font size, etc.

Step 1)

Create a new PHP file like “example.php” and put the below code inside that file with PHP starting and ending code.

header(“Content-type: application/vnd.ms-word”);
header(“Content-Disposition: attachment; Filename=SaveAsWordDoc.doc”);

$html = "<meta charset="utf-8">
<title>A simple, clean, and responsive HTML export to Ms Word</title>
<style>body {height: 297mm;width: 210mm;margin: 0 auto;font-size: 10pt;line-height: 10pt;font-family:  Times New Roman, Arial, sans-serif;color: #000;}/style>
<form>
<table style="width:210mm;" width="100%" cellspacing="0" cellpadding="5" border="0">
<tbody>
<tr>
<td>REF No: 123456&lt;/td>
</tr>
<tr>
<td><strong>Date: 24 October 2019 </strong></td>
</tr>
<tr>
<td>
        Dear USER NAME</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tbody>
<tr>
<td width="30">
<div style="border: solid 1px #000; margin: 2pt; float: left;">&nbsp;</div></td>
<td>&nbsp;USER data.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>";
echo $html;

Step 2)

Now you can run this file to your browser. you can get your HTML or text to Ms-word file. this will support in each and every browser.

How to Work Mpdf Workable in Php 7 ?

pdf_mpdf

If you use an old version of PHP in your local system and you integrate the mpdf in that old version. after you change your PHP version to the latest version and mpdf is not working then simply follow our below steps and you will get the mpdf working in your latest PHP version.

Step 1)

Click here to download the mpdf.

Step 2)

Include the mpdf

require_once _DIR_ . ‘/MPDF/vendor/autoload.php’;

instead of

require_once( ‘mpdf/mpdf.php’);

Step 3)

Just change your code to

$html = “Your html code here”;
$mpdf = new \Mpdf\Mpdf([‘mode’ => ‘utf-8’, ‘format’ => ‘A4′,’0′,”,0,0,0,0,’margin_header’ => 0,’orientation’ => ‘P’]);
$mpdf->setAutoTopMargin = ‘stretch’;
$mpdf->setAutoBottomMargin = ‘stretch’;
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;

Instead of

$html = “Your html code here”;
$mpdf=new mPDF(‘utf-8’, ‘A4’, 0, ”, 0, 0, 0, 0, 0, ‘P’);
$mpdf->setAutoTopMargin = ‘stretch’;
$mpdf->setAutoBottomMargin = ‘stretch’;
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($html);
$mpdf->Output();

Step 4)

Now your mpdf is working in php 7 and above version.