Changing permalink settings, throwing 404 error in localhost? Solution for Ubuntu with Apache
Wordpress , PHP / May 18, 2020

Changing the permalink settings from plane to other options like Month and name/Other can cause a 404 error while you are running your WordPress in Ubuntu with Apache localhost.  This error can be quite annoying and here are the changes you should make to get rid of this error. To change permalink navigate to settings->permalinks.     We are running your WordPress site from folder /var/www/html/testfolder/wptest     Step 1 – Enable mode rewrite in Apache

Provides a rule-based rewriting engine to rewrite requested URLs on the fly. Now after enabling, restart  Apache

          Step 2 – Modify the Apache Config file Apache config file is  etc/apache2/apache2.conf. Open the file using the following command.

Find the following lines in the config file

replace this with the following. The AllowOverride ride is changed to All and require is changed to all granted.

AllowOverride directive is used to allow the use of a. htaccess within the webserver to allow overriding of the Apache config on a per-directory basis. Require provides a variety of different ways to allow or deny access to a resource.           Step 3 – Restart Apache…

Disable WordPress comment box, on reaching a specific number of comments or if user already posted specific number of comments.
Wordpress , PHP / May 6, 2020

Imagine a use case in which the comment box has to be disabled On reaching a specific number of comments in WordPress post If the user already posted a comment For applying these conditions, the following data are needed Number of comments in a post Number of comments of a User in a WordPress Post   Obtain the number of comments in a WordPress Post To obtain the number of comments in a post, the following built-in function  get_comments_number, can be used.

    Obtain  the number of comments of a User in a WordPress Post To obtain the number of comments in a post, by the logged-in user, the following built-in function  get_comments, can be used.

  Navigate to the themes folder, comment_form  function in comments.php usually outputs the comment form. A condition has to be applied before calling this function.

  On using plugins, this might not work depending on the plugin For more information read the following documentation for built-in functions This approach helps in preventing spam comments.

Creating a Cron job in Laravel 5.2 :Task Scheduling
PHP , Beginner , Snippets / July 23, 2018

To create a cron job in Laravel 5.2 ,move to the app/console/ folder.The console folder contains all the relevant configuration files and folders for you to create a custom artisan command in Laravel 5.6 .  After creating the custom artisan command ,we can schedule the command to be run in specific intervals Step 1 Run

  to create new custom artisan command,This will generate a class called app/Console/Commands/CronJob.php.The newly generated file will have the following structure.You have to fill in name and description variables in the file.You can use the DB and MODEL files from CronJob.php. The file extends the Command Class   app/Console/Commands/CronJob.php

Here we select a set of users based on some custom criteria from the users table and do something to them periodically with the cron job.The action for the should be written in the CronJob.php – handle() function.The class defines our command.To run this need to use the following php artisan cronjob Step 2 Scheduling the job To schedule the when to run the command we have created open the kernel.php file in the app/console/ folder app/console/kernel.php

The kernel class extends ConsoleKernel .To add the commands

and to schedule the command

  This runs…

How to display user – display name,avatar and logout button in WordPress : Example
Wordpress , PHP , Beginner , Snippets / July 8, 2018

To display user displayname , avatar and provide a logout button for a user in your wordpress site,we can use the following  five worpress functions. is_user_logged_in () –  Check whether used in. wp_get_current_user(id/email,null)  –  Get current logged in user get_avatar_url(userid) – Get avatar url for current user using userid wp_logout_url(url) – Logout and redirect URL home_url() – Get your home URL  

  Check below links to see documentation in full        

How to change ‘sql_mode’ in mysql
PHP , Uncategorized / July 2, 2018

To see Mysql mode settings,do the following query. Mysql mode is not linked to any particular database. Modes can be set locally to the session (connection), or for the server globally.

This gives results like below   Now to change sql_mode,you need to run query like this

Example Some times after  importing database and changing some table structure,you may get an error like this. This is because NO_ZERO_IN_DATE and NO_ZERO_DATE is enabled in and database has invalid date values. NO_ZERO_IN_DATE The NO_ZERO_IN_DATE mode affects whether the server permits dates in which the year part is nonzero but the month or day part is 0. Example – ‘2010-00-01’ or ‘2010-01-00’ NO_ZERO_DATE This mode is deprecated This determines whether the server permits ‘0000-00-00’ . NO_ZERO_IN_DATE also depends on whether strict SQL mode is enabled. Removing above modes from sql_mode  lets the server allow invalid dates in the aforementioned format     Or to set it PERMANANTLY, change etc/my.cnf

and restart WHAT is sql_mode Server SQL modes determine what SQL syntax MySQL should support and what kind of data validation checks it should use. This makes it easier to use MySQL in different environments. See more on  list of sql…

What are cookies and how to set and get them with Javascript

Cookies are data stored as text files in the computer.They are used store data that are needed to be remembered , like user information.Cookies can be set in client side and server side. For example,consider a user sign in to your website.The server sends back some response.The response have a token/id that can be stored as a cookie.This cookie value can keep the users details status in the client side. Cookie has a name and value pair,expiry time,path and secure . The security flags that are used to provide more security HttpOnly – HttpOnly flag sets the cookie unavailable to client side scripts.This prevent cross site scripting attacks(XSS) secure – Sets cookie to be send via a secure encrypted channel.Browser will send cookie only via an HTTPS request and prevent sending cookie via HTTP request. setcookievalue This function has three arguments name – cookie name. value – value of the cookie. hours- hours determine the expiry hours. document.cookie lets us store the cookie associated with the current document. getCookie This function has one argument ,cookie name document.cookie gets all the cookies associated with the current document.A cookie with a specific name can be obtained using the getCookie function.   getCookievalue This function has…

An introduction to Eloquent ORM in Laravel
interview questions , PHP , Uncategorized / June 20, 2018

ORM refers to Object Relational Mapping.What ORM tools like  Eloquent does is that they are equipped with a metadata descriptor which helps in connecting object code to a relational database.To learn more on ORM refer this article. Now,we know that sequelize is an ORM tool that is used to connect node applications to relational databases such as Mysql/postgres.For PHP Developers ,Laravel is equipped with a very simple,efficient ORM called Eloquent ORM. Using Eloquent To create model class we use the following command

Now in case you dont know,Artisan is a command line interface provided with Laravel just like the other command line interfaces you might have used,like angular-cli,Artisan helps you to generate files while working with Laravel. The above command creates a model file for our Table and it looks like this

As you can see all models extend “Illuminate\Database\Eloquent\Model” Also note that the table has ‘snake case plural’ name of the class.That is ‘televisions’ table and ‘television’ class.Uncomment the $table variable in the above code to use custom table name. Now,To generate a migration script on creating the model.This can be done using the following command.

The migration file looks like this

To run the…

Implementing priority queue in PHP
PHP , programming concepts / June 2, 2018

Queue is a First In First Out(FIFO) Data Structure.In a priority queue, an element with high priority is served before an element with low priority.The Standard PHP Library has the SplPriorityQueue class which can be used to implement priority queue.The insert(‘item’,priority) method is used to insert item and the corresponding priority in to the queue.See the below example to see mail sending to different mail id’s that have different priorities.You can use while to iterate thorough the queue and process each one or the results. SplPriorityQueue A priority queue can be implemented using many of the data structures that we’ve already studied (array, inked list, binary search tree). However, those data structures do not provide the most efficient operations. To make all of the operations  efficient, heap can be used . SplPriorityQueue is implemented using Max Heap


PHP / May 31, 2018

In this section we will look at OOP with PHP . Refering the below explanations prior to interviews will surely help you to answer some of the most common questions an rookie/intermediate level developer might face in interviews.Here is a diagram depicting object oriented programming concepts CLASSES In object-oriented programming , a class is a template definition of the method s and variables in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables.

A CLASS is a template of an object.An OBJECT  is an instance of class

DATA ABSTRACTION Concept of Abstraction in PHP is important php oop (object oriented programming) concept.To show the needed/relevant information or details without showing all information which is not necessary is called abstraction.   Abstract Classes. – An abstract class is a class that is only partially implemented by the programmer. It may contain one or more abstract methods. An abstract method is simply a function definition that serves to tell the programmer that the method must be implemented in a child class.

    The constructor of a class defines what happens when you instantiate an object from this class. The destructor of a class defines what…

Share this page in social media platforms