Category: PHP

My favorite programing language.

Enhancing Web Security: A Guide to Content-Security-Policy and X-Frame-Options

Sure thing! Let's break down this code step by step: 1. Setting Security Headers header("Content-Security-Policy: frame-ancestors 'self' https://aicrafter.us https://qiksoft.com"); header('X-Frame-Options: SAMEORIGIN'); Content-Security-Policy (CSP): This header restricts which sources can embed your content in a frame. Here, it allows only the same origin ('self') and the specified domains

Flat-File Content Management System (CMS) Code

Creating a Content Management System (CMS) can be a daunting task, especially for those who are not familiar web development. However, with the right tools and knowledge, it is possible to build a "simple" flat-file CMS using PHP. A flat-file CMS is a lightweight and easy-to-use system that does not require a database to store content. Instead, it uses text files to store data, making it ideal

Serve Files Through a PHP Script

To allow your index.php (just example file name and folder name) script to access files in the assets/ folder, you can create a PHP script that reads and serves these files. This script will act as a proxy to access the files. For example, we can create a "file.php" script that takes a file identifier as a parameter and serves the corresponding file from the assets/ directory. <?php //

Show Content to SEO but Forward Users

Very simple process but use with care! Seriously, you really should think long and hard before using in any SEO campaigns. Used responsibly, this is a power tool. Using wreckfully can cause your site to be banned from search engine platforms, you have been warned. In this code, strpos function is used to check if the User-Agent string contains 'Googlebot' or 'bingbot'. If it does, it means the

Identifying Local & Network Drives in Windows 10+

Sometimes we need to identify local and network dives on Windows machines. Since Windows 10+ no longer support (or soon to be) wmic, needed a simple way to use PHP. $fso = new COM('Scripting.FileSystemObject'); $D = $fso->Drives; $type = array("Unknown","Removable","Fixed","Network","CD-ROM","RAM Disk"); foreach($D as $d ){ $dO = $fso->GetDrive($d); $s = ""; if($dO->DriveType == 3){ $n =

Sending Custom User Agents

You can send custom user agent in PHP script using stream context and file_get_contents function. Here is an example: $options = array( 'http'=>array( 'method'=>"GET", 'header'=>"User-Agent: My Custom User Agent Stringrn" ) ); $context = stream_context_create($options); // Replace with your URL $response = file_get_contents('http://example.com', false, $context); This example creates a

File Get Contents the Best Method

function fetchWebPage($url) { // Load the web page content $content = file_get_contents($url); // Check if the content is successfully loaded if ($content === false) { // If the web page doesn't exist, load a local file for error $content = file_get_contents('local_error_file.html'); } else { // Get the base URL $base_url = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST);

Domain to domain cURL / API restrict page access

You can pass the token using HTTP headers, or via a POST request which will make it invisible in the URL. Using this method the token ID is not present in the URL. Since you are redirecting from one domain to another using a GET request, this leaves the HTTP headers method as your only method to go about implementing this. Please be note that this only works in a server-to-server communication

Domain to domain SQLite restrict page access

Domain 1 controls the database while Domain 2 just acts according to the token verification result. In this scenario, Domain 2 will not directly access the database, but it will make a request to Domain 1 (verifyToken.php) to check whether a given token is valid or not. Domain 1 will return a response accordingly after checking the database, and Domain 2 will then grant or deny access based on