Showing posts with label Tips & Tricks. Show all posts
Showing posts with label Tips & Tricks. Show all posts
How to disable the browser back button navigation using javascript

How to disable the browser back button navigation using javascript

Hi, Today you will learn about "How to disable the browser back button navigation using javascript", In general, we don't use this type of requirement in the project.But is very useful in so many situations.

For example, we are doing in the online cart i.e an e-commerce platform so here after the placing the order and once the user checks out the order in his cart and payment completed it will redirect and shown the order success page after that user doesn't go back to the previous pages. So here we want to block the browser back button navigation.

So here in this situation we will use this code. if you searched on the internet you will find the code i.e
<script type="text/javascript">  
     window.history.forward();  
     function noBack()  
     {  
       window.history.forward();  
     }  
 </script>  
 <body onLoad="noBack();" onpageshow="if (event.persisted) noBack();" onUnload="">   
This code is not working properly. so I have found the solution to this problem. Just add the below script code on the file where the user doesn't go back from that file.
<script type="text/javascript">  
 (function (global) {   
   if(typeof (global) === "undefined") {  
     throw new Error("window is undefined");  
   }  
   var _hash = "!";  
   var noBackPlease = function () {  
     global.location.href += "#";  
     // making sure we have the fruit available for juice (^__^)  
     global.setTimeout(function () {  
       global.location.href += "!";  
     }, 50);  
   };  
   global.onhashchange = function () {  
     if (global.location.hash !== _hash) {  
       global.location.hash = _hash;  
     }  
   };  
   global.onload = function () {        
     noBackPlease();  
     // disables backspace on page except on input fields and textarea..  
     document.body.onkeydown = function (e) {  
       var elm = e.target.nodeName.toLowerCase();  
       if (e.which === 8 && (elm !== 'input' && elm !== 'textarea')) {  
         e.preventDefault();  
       }  
       // stopping event bubbling up the DOM tree..  
       e.stopPropagation();  
     };       
   }  
 })(window);  
 </script>  
Here you can check the demo.
Demo
* If you like this post please don't forget to subscribe TechiesBadi - programming blog for more useful stuff
How to read the .docx files in PHP

How to read the .docx files in PHP

Hi, In This tutorial you will learn about "How to read the .docx files in PHP". Generally .docx files will be opened in the MS-OFFICE, But we are able to open the .docx file in PHP we have to convert the .docx file into text then we can easily display the content in the web browser.

<?php  
 function read_file_docx($filename){  
      $striped_content = '';  
      $content = '';  
      if(!$filename || !file_exists($filename)) return false;  
      $zip = zip_open($filename);  
      if (!$zip || is_numeric($zip)) return false;  
      while ($zip_entry = zip_read($zip)) {  
      if (zip_entry_open($zip, $zip_entry) == FALSE) continue;  
      if (zip_entry_name($zip_entry) != "word/document.xml") continue;  
      $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));  
      zip_entry_close($zip_entry);  
      }// end while  
      zip_close($zip);  
      $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);  
      $content = str_replace('</w:r></w:p>', "\r\n", $content);  
      $striped_content = strip_tags($content);  
      return $striped_content;  
 }  
 $filename = "sample.docx";// or /var/www/html/file.docx  
 $content = read_file_docx($filename);  
 if($content !== false) {  
      echo nl2br($content);  
 }  
  else {  
      echo 'Couldn\'t the file. Please check that file.';  
           }  
 ?>  

* If you like this post please don't forget to subscribe TechiesBadi - programming blog for more useful stuff
How to Refresh a page after specific time automatically in PHP

How to Refresh a page after specific time automatically in PHP

Hi, In This tutorial you will know about How to Refresh a page after specific time automatically in PHP. Generally, we did this type of implementation in the javascript or jquery but sometimes javascript is disabled in the user's side (i.e users disabled the javascript in their browsers).

At this situation, we need to implement that code in PHP
it is very simple first we need to fix the specific time for the refresh the website.
In general, the header is used to redirect the web page in PHP by using the location. But here we will use the header in the Refresh tag to set the time and web page URL to refresh the web page.

 //getting the current web page url
 $page = $_SERVER['PHP_SELF'];
 //set the time in seconds
 $sec = "10";
 header("Refresh: $sec; url=$page");
* If you like this post please don't forget to subscribe TechiesBadi - programming blog for more useful stuff
How to Export and Download the Mysql Table data to CSV File in PHP

How to Export and Download the Mysql Table data to CSV File in PHP

Hi, You will learn in this tutorial How to Export and Download the Mysql Table data to CSV File in PHP. Sometimes you need to Export the user's data to CSV file because if a client wants to send the emails from the Autoresponders like Aweber, GetResponse, Mailchimp, etc..

In this case, you need to provide the user's contact information in the form of CSV file. It is a comma separated values so the human can read easily and exported CSV file can be imported on the Auto responders easily.

Related to Read : How to Upload CSV File into Database Using PHP and MYSQL

MySql Users Table
CREATE TABLE `users` (
  `user_id` int(11) NOT NULL,
  `user_first_name` varchar(100) NOT NULL,
  `user_last_name` varchar(100) NOT NULL,
  `user_email` varchar(255) NOT NULL,
  `user_country` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `users`
  ADD PRIMARY KEY (`user_id`);

ALTER TABLE `users`
  MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT;
Exporting the MySql table data to CSV file follow the step by step process

Step #1: Connect to the MySql Database in PHP
First let's connect to the database using the mysqli() object.
 <?php  
 $servername = "localhost";  
 $username = "root";  
 $password = "";  
 $dbname = "leads";  
 // Create connection  
 $con = new mysqli($servername,$username, $password, $dbname);  
 // Check connection  
 if ($con->connect_error) {  
 die("Connection failed: " . $con->connect_error);  
 }  
 ?>  
Step #2: Select the table and its columns from the MySql database
After connecting to the database, we need to fetch the records from the table.
If you want to export the entire table then execute this SQL Query "SELECT * FROM `users`"
otherwise, you need the custom columns then specify the column names in the Query "SELECT `user_first_name`,`user_email` FROM `users`".  Here I am taking the entire table 'users'.
 <?php  
 // Fetch Records From Table  
 $sql = "SELECT * FROM `users`";  
 $result = $con->query($sql);  
 ?>  
Step #3: Converting the MySql Results to CSV file format
Now we have to convert the fetched records into CSV file one by one. First, we need to write the table headings after that write the each row of data into the CSV file.
 <?php  
 $output = "";  
 // Get The Field Names from the table  
 while ($fieldinfo=$result->fetch_field())  
 {  
 $output .= '"'.$fieldinfo->name.'",';  
 }  
 $output .="\n";  
 // Get Records from the table  
 while ($row = $result->fetch_array()) {  
 for ($i = 0; $i < $columns_total; $i++) {  
 $output .='"'.$row["$i"].'",';  
 }  
 $output .="\n";  
 }  
 ?>  
Here each and every table records are saved in the form of the comma separated value format in the $output.

Step #4: Download the Exported CSV file.
Here we need to specify the CSV file name and add the PHP headers application/csv and then add the attachment header this will force to downloaded the CSV file in the Browser.
 <?php   
 // Download the CSV file  
 $filename = "myFile.csv";  
 header('Content-type: application/csv');  
 header('Content-Disposition: attachment; filename='.$filename);  
 echo $output;  
 ?>  
Complete PHP code to Export and Download the MySql Table data to CSV File
 <?php  
 $servername = "localhost";  
 $username = "root";  
 $password = "";  
 $dbname = "leads";  
 // Create connection  
 $con = new mysqli($servername,$username, $password, $dbname);  
 // Check connection  
 if ($con->connect_error) {  
 die("Connection failed: " . $con->connect_error);  
 }  
 // Fetch Records From Table  
 $output = "";  
 $sql = "SELECT * FROM `users`";  
 $result = $con->query($sql);  
 $columns_total = mysqli_num_fields($result);  
 // Get The Field Names from the table  
 while ($fieldinfo=$result->fetch_field())  
 {  
 $output .= '"'.$fieldinfo->name.'",';  
 }  
 $output .="\n";  
 // Get Records from the table  
 while ($row = $result->fetch_array()) {  
 for ($i = 0; $i < $columns_total; $i++) {  
 $output .='"'.$row["$i"].'",';  
 }  
 $output .="\n";  
 }  
 // Download the CSV file  
 $filename = "myFile.csv";  
 header('Content-type: application/csv');  
 header('Content-Disposition: attachment; filename='.$filename);  
 echo $output;  
 exit;  
 ?> 
Here you can download the Full Source code and check the demo.

Download Demo
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff

How to send the bold, italic text in skype chat

Hi, In this tutorial, I am going to explain How to send the bold,italic text in Skype chat.

Generally, in skype chat we send the normal text if you want to send the bold, italic, cross-out text and the combination of the bold and italic text. Just use some symbols before and after the text.

* for bold text, _ for italic text, ~ for cross-out text.
Usage
Bold text : *your text*
Italic text : _your text_
Cross-out text : ~your text~
Both bold and italic text : *_your text_*

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff

How to import the Excel sheet data into MySql database

Hi, In this tutorial, I am going to explain  How to import the Excel sheet data into MySql database.

Some of the organizations are uses the Excel sheets to save their data. When they want to upgrade their system with new technologies. Then we need to convert the entire Excel sheets data into SQL format.

For example, consider the one of the major organization is school
In school, so many students records are stored in the Excel sheet. Now we would like to import all those Excel data into SQL. Generally, this can be achieved by using the ODBC connections using any programming language. But it is somewhat difficult.

I will explain How to import the Excel sheet data into MySql database in the simplest way.
There's a simple online tool that can do i.e sqlizer.io
Here You can upload an XLSX file to it, enter a sheet name, cell range, and database table name. Here student.xlsx contains the student's data i.e there in the Sheet1, cell range is A1:E11 and MySql database table name is student.


After providing this information whenever you press the Convert My File button. Then it will generate a CREATE TABLE statement and a bunch of INSERT statements.
CREATE TABLE student (
    `id` INT,
    `fullname` VARCHAR(13) CHARACTER SET utf8,
    `gender` VARCHAR(7) CHARACTER SET utf8,
    `mobilenumber` INT,
    `city` VARCHAR(6) CHARACTER SET utf8
);
INSERT INTO student VALUES (1,'M.Rajkumar','Male',9959950011,'Guntur');
INSERT INTO student VALUES (2,'Ch.Eswar','Male',9959950011,'Guntur');
INSERT INTO student VALUES (3,'M.Srikanth','Male',9959950011,'Guntur');
INSERT INTO student VALUES (4,'Syed. Rehaman','Male',9959950011,'Guntur');
INSERT INTO student VALUES (5,'N. Nagendra','Male',9959950011,'Guntur');
INSERT INTO student VALUES (6,'D.Naveen','Male',9959950011,'Guntur');
INSERT INTO student VALUES (7,'G.Manohar','Male',9959950011,'Guntur');
INSERT INTO student VALUES (8,'P.Mahalaxmi','Fe Male',9959950011,'Guntur');
INSERT INTO student VALUES (9,'V.Vasavi','Fe Male',9959950011,'Guntur');
INSERT INTO student VALUES (10,'P.Swapna','Fe Male',9959950011,'Guntur');
These statements are imported all your data into a MySQL database

Watch Demo
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff

How to enable php intl extension in XAMPP / WAMP

How to enable php intl extension in XAMPP / WAMP

What is the php intl extension. It is a Internationalization extension. It is useful for formatting currency, number and date or time as well as UCA-conformant collations, for message formatting and normalizing text..etc

If you want to enable the php intl extension .Follow these steps.

Step #1:
Open the [xampp / Wamp path]/php/php.ini file
Now search for the extension=php_intl.dll
By default it is in commented mode
;extension=php_intl.dll 
Just remove the ; ( semicolon)
extension=php_intl.dll 
Then save the php.ini file

The latest versions of servers are supported just this minimal setting in the step #1.
Just restart your server for take effect the new changes.

If you got any warnings while your  server starts continue the below steps .Otherwise you did n’t get any warnings while your server starts then your  php intl extension is enabled successfully.

Step #2:
Browse the your server installation path like this
  
|-[xampp / Wamp path]/
|   |-php/
|   |  |-icudt57.dll
|   |  |-icuin57.dll
|   |  |-icuio57.dll
|   |  |-icule57.dll
|   |  |-iculx57.dll
|   |  |-icutu57.dll 
|   |  |-icuuc57.dll
Copy all these icu*.*.dll files from [xampp / Wamp path]/php to [xampp / Wamp path]/apache/bin

Now restart your server it takes effect.

When server starts you get  error 'MSVCR100.dll' is missing.
Now fix this error

Step #3:
You have to download the missing .dll file from here
https://www.microsoft.com/en-sg/download/confirmation.aspx?id=30679
Download the vcredist_x64.exe file and install them in to your system after installation restart your server to take effects.
Now php intl extension is enabled successfully.

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff
How to delete the entire directory with in its files in php

How to delete the entire directory with in its files in php

Generally we use the remove directory rmdir() method. In this case the directory will be removed when it has no files on it.
another way is unlink() method. This method can be used for removing the single file from the directory location.

How to download the multiple directories as a zip file in PHP

If you want to remove the directory and its all files and sub directories.
First removes the sub directories and its files after that removes the main directory. This is called as the recursion.
 <?php  
  function deleteDir($dirPath) {  
   if (! is_dir($dirPath)) {  
     throw new InvalidArgumentException("$dirPath must be a directory");  
   }  
   if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {  
     $dirPath .= '/';  
   }  
   $files = glob($dirPath . '*', GLOB_MARK);  
   foreach ($files as $file) {  
     if (is_dir($file)) {  
       deleteDir($file);  
     } else {  
       unlink($file);  
     }  
   }  
   rmdir($dirPath);  
 }  
 deleteDir("Directoryname");  
 ?>  

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff
How to include CSS and JS files via HTTPS

How to include CSS and JS files via HTTPS

Generally we include the CSS and JS files are in the below format.
<link rel="stylesheet" href="http://example.com/style.css">  
<script src="http://example.com/script.js">
The links are works perfect in the normal protocal like http://example.com .when we move to the SSL enabled site i.e https://example.com.

In this case above inlcuded CSS and JS files are not works perfectly because of it use's the protocol relative paths.

To avoid these problem's load your CSS and JS files in the below format.
 <link rel="stylesheet" href="//example.com/style.css">  
<script src="//example.com/script.js"></script>
Then it will use the protocol of the parent page.
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff
How to increase the php file upload limits

How to increase the php file upload limits

PHP has several configuration options to limit resources consumed by scripts. By default, PHP is set to allow uploads of files with a size of 2MB or less.
Now you can change these configuaration.
Follow these steps
Step 1: open your server root directory
Step 2: open the php directory
Step 3: open the php.ini file

Try increasing the following values in php.ini, for example:
 
memory_limit = 32M
upload_max_filesize = 50M
post_max_size = 50M
After making these changes, you may need to restart Apache for this new changes to take effect.

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff

How to increase the import file size in phpmyadmin

In general phpmyadmin allows to import file size Max: 2,048KiB
By default you get a 2mb limit of import size in phpmyadmin.It is impossible to import larger files. You can increase the allowed import size of phpmyadmin by editing your server's php.ini configuration file. Usually it is located at {Server}/Php/php.ini.
Here Server is WAMP, XAMPP, VERTRIGO.
Step 1: Go to php.ini and find the upload_max_filesize and post_max_size
Default values
 
upload_max_filesize = 2M
post_max_size = 8M

Change their values to higher value
  
upload_max_filesize = 50M
post_max_size = 50M
Step2 : Restart your server for this new change to take effect.
            Now you can import the larger files easily.

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff

How to register the facebook account with out your original information

Today I will explain how to register a Facebook account with out your original email address and mobile number.
This tutorial is only for educational purpose. Don't misuse this technique.

Do you know about any disposable email systems? . What do you mean by the disposable email?
It is temporary email address you can get very easily and when you create the temporary email immediately it receives the email. After a certain time that email will be deleted.

User no need to register for the disposable service. There are many disposable email providers in the internet
Top 10 disposable email websites

1. Mailinator 
2. Throw away mail 
3. 10minutemail
4. Guerrillamail
5. Getairmail
6. Yopmail 
7. Mytemp 
8. Maildrop
9. Fake inbox
10. Email on deck

Now follow these steps:

Step 1: get one disposable email from above any one of the email service websites.
Step 2: open the Facebook account

Now fill all the data in the  registration like name,gender, in email give your disposable email address after creation of the Facebook account one email will be sent to your disposable email account for conforming the email address just open the email and confirm the account registration.

That's it now your Facebook account is created with out your personal details.
Don't misuse this technique.

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff