watermark_naijaT


For the sake of security, it is advised to put some important files outside of the public_html directory on your web host directory. In this tutorial, I will be showing how to put files outside of the public_html directory and accessing those files from the public_html.

When a website is accessed from every web browser, they serve request from the public_html directory which makes the public_html directory susceptible to attack from intruders. Files that contains database configs like username and password can be kept outside the public_html directory.

Going straight into the tutorial, I will be using php to create a function that can return files outside of the public_html directory. For example, this is how public_html looks like; home/locations/public_html, so what i will be doing is to put  an important file here; home/locations/secret_file.php instead of putting it in home/locations/public_html/secret_file.php.

This below is the php script:


function call_in($filename){

$save_Url = $_SERVER['DOCUMENT_ROOT'];//outputs eg home/locations/public_html
$tell_pos = strrpos($save_Url, '/');//tells the position of  where '/' appeared last on a string.
return substr($save_Url, 0,$tell_pos) . '/'. $filename;//returns  eg home/locations/secret_file.php
}

This php function can be used anywhere in your public_html directory. You simply call the function and provide the filename you uploaded outside the public_html directory. You can upload your various files into your web hosting space via filezilla.

This way, you keep important files outside the public_html directory. If there are questions or explanations or other issues, you can use the comment section, or email naijatech06@gmail.com. Enjoyyyyyyyyyyyyyyyyyyy!!!!!!!!!!!!!!!!