PHP Interview Questions And Answers For 5 Year Experience

Question # 1) What is self in PHP?Answer # In PHP self keyword is used to access static properties and methods.Question # 2) What is $this?Answer # It is the way to reference an instance of a class from within itself, the same as many other object-oriented languages.  $this refers to the class you are in. In PHP, the pseudo-variable $this is available when a method is called from within an object context.Question # 3) When to use self over $this?Answer # Use $this to refer to the current object. Use self to refer to the current class.Question # 4) What is the difference between Apache and Tomcat?Answer # Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat. So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.Question # 5) What is Nginx and what is it used for?Answer # NGINX (Pronounced as Engine-X) is an open source, lightweight, high-performance web server or proxy server. Nginx used as reverse proxy server for HTTP, HTTPS, SMTP, IMAP, POP3 protocols, on the other hand, it is also used for servers load balancing and HTTP Cache.Question # 6) Which is the best Web server?Answer # There are different web servers available for different technologies.LAMP: Linux, Apache, MySQL and PHP.WIMP: Windows, IIS, MySQL/MS SQL Server and PHP.WAMP: Windows, Apache, MySQL/MS SQL Server and PHP.LEMP: Linux, NGINX, MySQL and PHP.Question # 7) What is .htaccess in PHP?Answer # .htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn ‘loaded via the Apache Web Server’, then the .htaccess file is detected and executed by the Apache Web Server software.Question # 8) What are advantages of .htaccess?Answer # There are many advantages using .htaccess file in PHP:URL redirectingManaging error pagesPassword ProtectionVisitor blocking facilities by IP addressSetting Config variable and Environment variableQuestion # 9) How to redirect a URL from http to https in .htaccess?Answer # Using this below code, we can redirect a URL from http to httpsRewriteEngine onRewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]Question # 10) How to redirect https to http URL and vice versa in .htaccess?Answer # Using this below code, we can redirect a URL from http to httpsRedirect https to httpRewriteEngine OnRewriteCond %{HTTPS} onRewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

admin
Author: admin

Leave a Reply