Search for a word/text within all PHP files of a directory

<?php $path = getcwd(); // replace with the directory path [if you know the directory already] $filename=filepath($path); function filepath($dir){ $count_size = 0; $count = 0; $dir_array = scandir($dir); foreach($dir_array as $key=>$filename){ if($filename!=”..” && $filename!=”.”){ echo $filename; echo “<br>”; $file = $filename; $searchfor = ‘ajax’; // the following line prevents the browser from parsing this as […]

Read More

file_get_contents alternative:PHP

If file_get_contents is not working, you can use CURL. <?php //$message=file_get_contents(SERVER_PATH.’admin/emails/’.); $curlSession = curl_init(); $template_file_name=email_template.html; //replace with your filename curl_setopt($curlSession, CURLOPT_URL, SERVER_PATH.’admin/emails/’.$template_file_name); curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true); curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true); $message= curl_exec($curlSession); curl_close($curlSession); echo $message; ?>

Read More

Call more than one file using curl:PHP

Following is the script to call multiple files using curl. <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); $ch3 = curl_init(); // set URL and other appropriate options curl_setopt($ch1, CURLOPT_URL, “http://path/to/file1.php”); curl_setopt($ch1, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_URL, “http://path/to/file2.php”); curl_setopt($ch2, CURLOPT_HEADER, 0); curl_setopt($ch3, CURLOPT_URL, “http://path/to/file3.php”); curl_setopt($ch3, CURLOPT_HEADER, 0); //create the multiple cURL handle […]

Read More

CURL with parameters:PHP

Following is the script used for passing parameters using CURL: <?php // create curl resource  $ch = curl_init(); // is cURL installed yet? if ($ch){   //     echo (‘ cURL is  installed!’); }       // set url       echo $set_url = curl_setopt($ch, CURLOPT_URL, “http://your/file/path/filename.php”); if($set_url) { // echo “URL SET”; […]

Read More

Count Number of Columns That Are Not Empty:PHP MYSQL

Hello friends, I have written the following script to count the columns which are not empty. In the following script i have taken a scenario where student’s batch-days are supposed to be counted.   <?php $sql=”SELECT sum((monday_time_from IS NOT NULL and monday_time_from <> ”) + (tuesday_time_from IS NOT NULL and tuesday_time_from <> ”) + (wednesday_time_from […]

Read More

Send Email With Attachment:PHP

The following code should be used if you want to send an email with an attachment. Here we will attach zip file in the email. <?php $email_to = “developergirls8@gmail.com”; // The email you are sending to $email_from = “intelitabs@gmai.com”; // The email you are sending from $email_subject = “Passed Students”; // The Subject of the […]

Read More

Create zip file using PHP

Following is the code to create a zip file. //call a function $create_zip=create_zip(); //create function. function create_zip($passed) { $mypath=SERVER_ROOT_PATH.”download/”; //change path as per need $destination = SERVER_ROOT_PATH.”download/progress.zip”; //change filename as per need $overwrite = false; //echo $mypath; //if you have already have files of which you want to create zip file,then use following code: $temp […]

Read More

Delete all the files inside folder:PHP

Did you ever come across a situation where you want to delete all the file with a particular extension from the folder? The following code should be used To delete all the files present inside the folder: //Here I want to delete all the word documents inside download folder. <?php $mypath=”public_html/download”; //replace it with your […]

Read More

Insert into more than 1 database:PHP

I have a table called vendor_keys. It has 2 fields: 1. vendor_name 2. key_provided. The Same table is inside 3 databases.And I want to insert the details into all 3 databases at once. Following is the code to insert details into 3 databases. <?php header(“Access-Control-Allow-Origin: *”); $vendor_name=$_POST[‘vendor_name’]; $key_provided=$_POST[‘key_provided’]; $password=$_POST[‘password’]; $servername = “localhost”; $username = “root”; […]

Read More

Form With Generate Password/Key Field: PHP

I have written this blog to generate 24 digit alphanumeric key/password while creating the signup form. CREATE A PHP FILE AND PASTE FOLLOWING CODE INTO IT. <html> <body> <h1><b>ADD VENDOR</b></h1> <form method=”POST” action=”#”> [replace # with the file path] <table> <tr><td>VENDOR NAME:</td><td><input type=”text” name=”vendor_name” required></td></tr><tr><td> <tr><td> KEY:</td><td><input type=”text” name=”key_provided” value=”<?php echo $password = random_password(24);?>” size=”35″ […]

Read More