Posts

Showing posts with the label PHP

Function Overloading And Overriding In PHP

Image
  Function overloading and overriding is the Object Oriented Programming feature in PHP. Function overloading means multiple function have the same name but different parameters. But in case of function overriding, more than one functions will have same method signature and number of arguments. PHP doesn’t support function overloading directly like other languages such as C++, JAVA etc. But we can overcome this issue with using the PHP magic method __call(). So let’s see how overloading and overriding in PHP works. Function Overloading In PHP Function overloading contains same function name and that function performs different task according to number of arguments. Example <?php class Shape { const PI = 3.142 ; function __call($name,$arg){ if($name == 'area') switch(count($arg)){ case 0 : return 0 ; case 1 : return self::PI * $arg[0] ; case 2 : return $arg[0] * $arg[1]; } }

The Requested Url /Phpmyadmin/ Was Not Found On This Server

Image
  What Is phpMyAdmin phpMyAdmin is an open-source software tool introduced on September 9, 1998, which is written in PHP. Basically, it is a third-party tool to manage the tables and data inside the database. phpMyAdmin supports various type of operations on MariaDB and MySQL. The main purpose of phpMyAdmin is to handle the administration of MySQL over the web. phpMyAdmin has a GUI application which used to mange the database. Here we can create a database, table and execution of mysql query using phpMyAdmin GUI Our Problem  : phpMyAdmin url not found. Here you will find the  Solution Here

What is difference between get and post method in php

What is HTTP? The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. Two HTTP Request Methods commonly used for request-response between a client and server: GET and POST The GET Method Following example which shows you how to use get method. http://www.example.com/test/demo_form.php?name1=value1&name2=value2 Following are GET Request Method Points. 1. Request can be cached 2. Requests can be bookmarked 3. Requests remain in the browser history 4. Requests have length restrictions 5. Requests should be used only to retrieve data 6. Requests should never be used when dealing with sensitive data 7. Maximum path length of 2,048 characters 8. Data visible to everyone in URL. 9. GET is less secure compared to POST because data sent is the URL. Following are POST Request Method Points. 1. Requests are never cached 2. Requests do not remain in

Magento – Newsletter's emails stuck in Queue

Image
If you are scratching your head to figure out why not Magento sending newsletter email. Here we got the same problem. You can check on Problem with Solution. Problem We installed newsletter pop up extension which was working fine. But after some days we saw newsletter emails are not working. We tried many solutions, Check Magento newsletter setting and also check cronjob code. But no luck. Then we have tried to uninstall recently installed extensions on the server then we found MailChimp and Newsletter POP extension are conflicting with each other. If you have a facing same problem then you can apply the following solution 1. First, check cronjob properly set or not. sudo crontab -e */5 * * * * /path/to/php -f /path/to/cron.php  2. This solution we found on ebizmarts forum. Comment out line 118 of app/code/community/Ebizmarts/MailChimp/Model/Observer.php //$subscriber->setImportMode(true); //commented out to enable Magento to send emails In app/code/communit

Free AWS EC2 Ubuntu Instance Website setup

Image
Amazon Web Service is a cloud platform which given us to create free hosting in both platform like Windows and Linux. Here we are working on Ubuntu setup. Where we will install Apache2, PHP and MySQL. 1. First you have to create new account in AWS. If you have existing account then no need to create. 2. After login you have to select EC2 option then you enter EC2 Dashboard. 3. Click Launch Instance 4. Select Free tier Eligible Ubuntu option. 5. Add New Volume EBS. 6. Add New Tag. 7. Add Security Group.   Type : SSH   Protocol: TCP   Port : 22   Source : Anywhere   Type : HTTP   Protocol : TCP   Port : 80   Source : Anywhere 8. Review and Launch 9. Create a New Pair Key. Download Key. 10. Using Puttygen.exe software create public and private key. 11. Login SSH using putty.exe Now we are ready to install Apache2, PHP, MySQL. Command 1 ( Update Ubuntu server ) sudo apt-get update sudo apt-get dist-upgrade Command 2 ( Install apache2 server ) sud

Login SSH using Putty.exe

Image
Login SSH using Putty.exe Putty is an SSH and Telnet client software, developed by Simon Tatham for the Windows platform. Putty is open source software Follow below steps which can help you to login SSH using putty. 1. Download Putty.exe 2. Enter IP. 3. Select PPK file path provide by your hosting provider or if you are using AWS then you will get ppk file from there also.

How to clear the cache of client browsers?

Image
Hello friends today we will learn how to clear the cache client browsers. This technique is very simple. Just add a version parameter to the URL string which is either a random string or a random number. If you change your sites CSS and upload on the server you will get old result only. For solve this problem, simply add ?ver=1.1 to the CSS import at the head of the file. So the browser teat as a different file. Example: <link href="css/style.css" rel="stylesheet" type="text/css" /> Becomes <link href="css/style.css?ver=1.1" rel="stylesheet" type="text/css" /> Same you can apply for JavaScript files.

How to send emails using PHPmailer and GMAIL SMTP

Image
Here I have tried how to send PHPMailer with attachement using SMTP configuration. For SMTP Configuration we here used GMAIL Auth. You can used any Auth like SMTP2GO , SendGrid . Download PHPMailer library. PHPMailer Sample Code Addd or Copy paste the following code in your editor and save with any filename with extension ".php" and try in your live server or local server. But Make sure you have to connect with internet with proper Auth details <?php require_once('phpmailer/PHPMailerAutoload.php'); $mail = new PHPMailer(); $mail->CharSet = "utf-8"; $mail->IsSMTP(); // Set mailer to use SMTP $mail->SMTPDebug = 1; // Enable verbose debug output $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = "xxx@example.com"; //Your Auth Email ID $mail->Password = "xxxxxx"; //Your Password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Host = "

Import CSV to Database using PHP

Import csv database using PHP. Follow the following code and you will done with CSV import script using PHP. If you have any questions you can feel free comment we will reply you ASAP. PHP Code <?php if(isset($_POST["Import"])) { $filename=$_FILES["file"]["tmp_name"]; if($_FILES["file"]["size"] > 0) { $file = fopen($filename, "r"); mysql_query('truncate table table'); while (($data = fgetcsv($file, 10000, ",")) !== FALSE) { $sql = "INSERT into table(name,email,avg,sr,runs,wickets,hs,sixes,fours,longsixes,created) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]', now())"; mysql_query($sql); } fclose($file); echo

Enabling Gzip Compression of PHP, CSS, and JS Files Without mod_deflate

For enable Gzip compression using mod_deflate add following lines to your .htaccess file AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript But those who don’t allow the mod_deflate module and run PHP in CGI/FastCGI mode you can’t go with the easy method. So, to serve up your PHP, CSS, and JS files you can try the following method. Step 1: PHP Configuration Add or modify the following lines in your custom php.ini file output_handler = Off zlib.output_compression = On zlib.output_handler = ob_gzhandler Now this will take care of gzipping all PHP files. Step 2: .htaccess Configuration Add the following lines to the bottom of a .htaccess file in the root of your website. RewriteEngine On RewriteRule ^(.*\.js) gzip.php?type=js&file=$1 RewriteRule ^(.*\.css) gzip.php?type=css&file=$1 This will redirect all css and js requests files through gzip.p

How to work code-igniter project in sub-folder

When this happens when you have 2 .htaccess files in the server. Very simple solutions just add following code and your code-igniter project will work in sub-folder. RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /admin/index.php?/$1 [L]

CodeIgniter Subfolder .htaccess setup

When you are going to setup  CodeIgniter in live sufolder. There you need to create .htaccess file. RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /admin/index.php?/$1 [L]

Random post generate in wordpress

You have to first know default args of wordpress <?php $args  = array(      'numberposts'      =>  5 ,      'offset'           =>  0 ,      'category'         =>  ,      'orderby'          =>  'post_date' ,      'order'            =>  'DESC' ,      'include'          =>  ,      'exclude'          =>  ,      'meta_key'         =>  ,      'meta_value'       =>  ,      'post_type'        =>  'post' ,      'post_mime_type'   =>  ,      'post_parent'      =>  ,      'post_status'      =>  'publish' ,      'suppress_filters'  =>  true  );  ?> Use get_posts function and pass all the args which you have need. Example below Call function  <?php wp_get_theme_post(); ?>     in your templates Create function in function.php file   In if ( ! function_exists ( 'wp_get_theme_post'

CodeIgniter Session Destroy Problem SOVLED for Logout

We know what we need. Actually we are confused at that time. Its very easy. First time what we thinking their is a cookies or session problem. Not destroying fully or may be their global session created. But not like that ... Think Just think think... think... Solution : You have to submit the form using java script.  Our mistake is we are using anchor. Follow our examples:  IN HEAD TAG <script type="text/javascript">         function submitform()         {             document.myform.action="<?php echo base_url();?>user/logout";             document.myform.submit();         } </script> Where is your login link put under form tag <form action="" name="myform" id="myform" method="post">  a href="javascript: submitform()">Logout</a> </form>

prime number example in php

Here we are going to know how to create Prime Number What is Prime Number  : Prime number divide only 1 or itself that is a prime number Following is Prime Number Logic in PHP Step 1. Start your variable from 2 Step 2. Set flag =0. Step 3. Start your second variable means j from 2 and check in condition j <= i/2 Step 4. if i%j equal to 0 then flag=1 and break. Step 5. if flag=0 then it is Prime Number   for($i=2;$i<=50;$i++) {     $flag=0;         for($j=2;$j<=$i/2;$j++)             if(($i%$j)==0)             {                 $flag=1;                 break;             }         if($flag==0)         echo $i."is a prime number<br/>"; }

unique alphanumeric password generator function

Alphanumeric Password echo randomPass(); function randomPass($minChar=4, $maxChar=10, $useChar='abcdefghijklmnopqrstu1234567890'){         $numChar = rand($minChar, $maxChar);     $numUsable = strlen($useChar) - 1;     $string = '';     for($i<0; $i<$numChar; $i++){         $rand_num = rand(0, $numUsable);         $string .= $useChar{$rand_num};     } return $string; }

Fatal error: Call to undefined function base_url() in CodeIgniter

Base URL error in CodeIgniter.     <b>Fatal error</b>: Call to undefined function base_url() in CodeIgniter     You can replace in your autoload.php file with following. $autoload['helper'] = array('url');      

About PHP language & CodeIgniter

Building web applications with PHP is a pretty simple process. As a PHP developer, you can develop practically anything, including database layers, form validation programs, file upload applications, and so on. Once you've mastered the foundations of the object-oriented programe and learned how to implement certain common design patterns in real-world conditions, you should be armed with a useful toolkit comprised of all sorts of classes and functions that can be used any number of times. Although you may not be aware of this fact, your toolkit can be considered a general PHP development framework. The end result of your own efforts and skills as programmer. Sometimes, there are certain situations when the capabilities offered by your own framework simply aren't good enough to fit the requirements of a particular application. In a case like this, you can either upgrade your framework, which will probably require coding additional classes and functions, or you can pick up a thi

PART 2 : Php Add Edit Delete Update Example for freshers

1. Use Part 1 instruction for table and database   2. Create  register.php <?php $con = mysql_connect("localhost","root",""); if (!$con){   die('Could not connect: ' . mysql_error()); } mysql_select_db("sampletest", $con); if($_GET['type'] == 'delete'){     $delquery = "delete from user where id='" . $_GET['id'] . "'";     mysql_query($delquery); }else if($_GET['type'] == 'update'){     $selquery = "select * from user where id='" . $_GET['id'] . "'";     $rsquery = mysql_query($selquery);     $arrquery = mysql_fetch_array($rsquery); } if($_POST['submitbutton'] == 'Add'){     $name= $_POST['name'];     $email= $_POST['email'];     $phone= $_POST['phone'];     $query= $_POST['query'];     $query = "insert into user (name, email, phone, query) values ('".$name."'

PART 1 : Php Add Edit Delete Update Example for freshers

1. Create  Database: 'sampletest' Create Table structure for table 'user' CREATE TABLE IF NOT EXISTS `user` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `name` varchar(250) NOT NULL,   `email` varchar(250) NOT NULL,   `phone` varchar(250) NOT NULL,   `query` varchar(250) NOT NULL,   PRIMARY KEY (`id`) ) 2. register.php <?php $con = mysql_connect("localhost","root",""); if (!$con){   die('Could not connect: ' . mysql_error()); } mysql_select_db("sampletest", $con); if($_GET['type'] == 'delete'){     $delquery = "delete from user where id='" . $_GET['id'] . "'";     mysql_query($delquery); }else if($_GET['type'] == 'update'){     $selquery = "select * from user where id='" . $_GET['id'] . "'";     $rsquery = mysql_query($selquery);     $arrquery = mysql_fetch_array($rsquery); } if($_POST['submitbutton'] == &