Get the size of an image in php


$img = get_headers(“YourimageURL.jpg”, 1);
print_r ($img);

// OUTPUT It returns araay of image detail
[0] => HTTP/1.1 200 OK
[Content-Type] => image/jpeg
[Content-Length] => 27781
[Connection] => close
[Cache-Control] => max-age=5184000
[X-XSS-Protection] => 1; mode=block
[X-Content-Type-Options] => nosniff
[X-Nginx-Cache-Status] => HIT
[X-Server-Powered-By] => Engintron
[Pragma] => public
[Vary] => Accept-Encoding
[Accept-Ranges] => bytes

Remove public from URL in Laravel

To remove public from URL in laravel you need to follow below steps.

Rename the server.php in the your Laravel root folder to index.php
Move all folder from public to root.
copy the .htaccess file from /public directory to your Laravel’s project root folder.

Note:- This is not a safe way. A safer way is place Laravel’s files outside your web server root and make the Laravel’s public directory your web server root. Route your website to public folder in place of public_html. You can do this with help of your server administrator.

What is self keyword in PHP

In PHP, you use the self keyword to access static properties and methods.

Below is the example to expalin self

Refer this code:

class ParentClass {
function test() {


function demo() {
echo ‘Example of self !’;

class ChildClass extends ParentClass {
function demo() {
echo ‘Return chlid class’;

$obj = new ChildClass();

In this example, self::demo() will always output ‘Example of self !’.
Now we can see that self refers to the class in which it is called.
So, you should use self only when $this is not available, or when you don’t want to allow descendant classes to overwrite the current method.

If we use $this in test method it will return “Return chlid class”;

Show queries in laravel


Laravel provides a database query builder. To see the query use toSql() in laravel.


$result = DB::table(‘users’)
->where(‘username’, ‘like’, ‘%admin%’)
->toSql() // to see the query which is executed
//  ->get()->toArray();  to get results

Laravel update record

Use Query Builder to update records, This is a sample:

Or Use another method to load DB

generate random number in php

To generate 6 digit random number code in php.

Following function will help you to generate random number.

function _generate_code(){
$character_set_array = array();
$character_set_array[] = array(‘count’ => 3, ‘characters’ => ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’);
$character_set_array[] = array(‘count’ => 3, ‘characters’ => ‘0123456789’);
$temp_array = array();
foreach ($character_set_array as $character_set) {
for ($i = 0; $i < $character_set[‘count’]; $i++) {
$temp_array[] = $character_set[‘characters’][rand(0, strlen($character_set[‘characters’]) – 1)];
return implode(”, $temp_array);

echo _generate_code();

What is friend function?

friend function

– Friend function is a friend of a class.
– It is allowed to access Public, private or protected data of that class.
– It can be declared anywhere in the class declaration
– It doesn’t have any effect of access control keywords like private, public or protected.

PHP cookies

PHP cookies
Cookies are text files stored on the client computer and they are kept of use tracking purpose. We can create and retrieve the cookie in php

Create Cookies With PHP

A cookie is created with the setcookie() function.After setting the cookies, they can be used when the next page is loaded by using $_COOKIE.
For each cookie this function has to be called separately.

Function to set cookie
Setcookie(name, value, expire, path, domain);

Here is the detail of all the arguments −

Name − This sets the name of the cookie and is stored in an environment variable called HTTP_COOKIE_VARS. This variable is used while accessing cookies.

Value − This sets the value of the named variable and is the content that you actually want to store.

Expiry − This specify a future time in seconds since 00:00:00 GMT on 1st Jan 1970. After this time cookie will become inaccessible. If this parameter is not set then cookie will automatically expire when the Web Browser is closed.

Path − This specifies the directories for which the cookie is valid. A single forward slash character permits the cookie to be valid for all directories.

Domain − This can be used to specify the domain name in very large domains and must contain at least two periods to be valid. All cookies are only valid for the host and domain which created them.

Security − This can be set to 1 to specify that the cookie should only be sent by secure transmission using HTTPS otherwise set to 0 which mean cookie can be sent by regular HTTP.

$cookie_name = “user”;
$cookie_value = “Test name”;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), “/set folder”);

Retrieving cookie value:

The cookie that is set can be retrieved as shown below:
Echo $_cookie[“user”];

You can check with cookie is st or not with Isset() function.

Switch case in PHP

The switch-case statement is an alternative to the if-elseif-else statement, which does almost the same thing. The switch-case statement tests a variable against a series of values until it finds a match, and then executes the block of code corresponding to that match.
case condition1:
case condition2:

Below is example to display a different message for each month.
Example »


$today = date(“m”);


case “01”:

echo “Current month  is January.”;


case “02”:

echo “Current month  is February.”;


case “03”:

echo “Current month  is March.”;




echo “It will return if case dows not exits.”;




Use break to prevent the code from running into the next case automatically

GET and POST Methos in PHP

Methods of Sending Information to Server

A web browser communicates with the server typically using one of the two HTTP (Hypertext Transfer Protocol) methods — GET and POST. Both methods pass the information differently and have different advantages and disadvantages, as described below.
The GET Method

In GET method the data is sent as URL parameters that are usually strings of name and value pairs separated by ampersands (&). In general, a URL with GET data will look like this:

Advantages and Disadvantages of Using the GET Method

Data sent by the GET method are displayed in the URL, it is possible to bookmark the page with specific query string values.
The GET method is not suitable for passing sensitive information such as the username and password, because these are fully visible in the URL query string.
Because the GET method assigns data to a server environment variable, the length of the URL is limited. So, there is a limitation for the total data to be sent.



echo “This GET example Name:, ” . $_GET[“name”] ;



<form method=”get” action=”<?php echo $_SERVER[“PHP_SELF”];?>”>

<label for=”inputName”>Name:</label>

<input type=”text” name=”name”>

<input type=”submit” value=”Submit”>


The POST Method

In POST method the data is sent to the server. Data sent through POST method will not visible in the URL.
It is more secure than GET because user-entered information is never visible in the URL query string or in the server logs.
There is a much larger limit on the amount of data that can be passed and one can send text data as well as binary data (uploading a file) using POST.

PHP provide another superglobal variable $_POST to access all the information sent via post method or submitted through an HTML form using the method=”post”.



echo “This post example Name:, ” . $_POST[“name”];



<form method=”post” >

<label for=”inputName”>Name:</label>

<input type=”text” name=”name” >

<input type=”submit” value=”Submit”>


PHP provides another superglobal variable $_REQUEST that contains the values of both the $_GET and $_POST



echo “This post example Name:” . $_REQUEST[“name”];



<form method=”post” >

<label for=”inputName”>Name:</label>

<input type=”text” name=”name” >

<input type=”submit” value=”Submit”>