Friday, 28 August 2020

Post data in API

  <head>

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

</head> 


<h1>Device Id Send with API</h1>


<div id="result">

....

</div>


<button>Add Device Id</button>

<script>

    $(document).ready(function () {

    

       $("button").click(function(){

            

                $('#result').html("");

                 

                $.ajax({

                    type: "POST",

                    url: "http://seemacollegeparbatsar.org/api/notification",

                    data: {'device_id': 'aaaaaa1'},

                    dataType: "json",

                     

                    success: function (data) {

                         

                        

                        $('#result').append(data);

 

                    } 

                });

             

        });

    });

</script>


Full Demo : https://www.itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html

Code Download : https://drive.google.com/file/d/1Xj9oTWvOFj5UrJh91BD4tKyc9gzX4XRB/view?usp=sharing

Tuesday, 18 August 2020

Using .htaccess to restrict access to Files and Directories

 

1. Deny Access to .htaccess Itself

Add the following lines in your .htaccess file to prevent access to .htaccess file itself.

# Deny access to .htaccess
<Files .htaccess>
Order allow,deny
Deny from all
</Files>


2. Disable Directory Indexing

The following line in .htaccess will remove directory indexing and make the server respond with a 403 forbidden message.

# Disable directory browsing 
Options -Indexes

To simply hide all the contents of the directory without forbidden message, use the IndexIgnore directive.

# Hide the contents of directories
IndexIgnore *

To hide some filetypes only, use

# Hide files of type .png, .zip, .jpg, .gif and .doc from listing
IndexIgnore *.png *.zip *.jpg *.gif *.doc

3. Prevent access to certain files

Even if you remove directories and files from listing, they are still accessible if you type the path.

To remove unauthorized access to cetain file extensions, use

# Deny access to files with extensions .ini, .psd, .log, .sh
<FilesMatch "\.(ini|psd|log|sh)$">
Order allow,deny
Deny from all

</FilesMatch>

To prevent access to all filenames starting with dot(.) like .htaccess, .htpasswd, .env and others use

# Deny access to filenames starting with dot(.)
<FilesMatch "^\.">
Order allow,deny
Deny from all
</FilesMatch>

You may also password protect files and directories and store the passwords in a .htpasswd file

# Password protect files
<FilesMatch "^(execute|index|myfile|anotherfile)*$">
AuthType Basic
AuthName "Mypassword"
AuthUserFile <Full Server Path to .htpasswd file>/.htpasswd
Require valid-user
</FilesMatch>

Directory data calculation in MB

 <?php 

/* Directory data calculation in MB */

function folderSize ($dir)

{

    $size = 0;

    foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {


 


        $size += is_file($each) ? filesize($each) : folderSize($each);

    }

    return $size;

}


?>

<?php 

$newsDIR =  folderSize("/home/apnaaagaz00/public_html/media");

echo round(($newsDIR/1024/1024)).' Mb';

?>