Category: PHP

My favorite programing language.

Domain to domain restrict page access

Need to restrict access to a page between domains? If your pages are on the same domain, you can use sessions. But what about two different domains? After much experimenting, I present a simple way to restrict page access between domains without a database. EXAMPLE 1: Code for referring domain: <?php $secretKey = '0101010'; $secondDomainURL = 'https://qikgraphics.com/1/banner/creator.php'; //

Send a session value from one page to another

To send a session value from one page to another using a URL, you can include the session value as a query parameter in the URL. Here are a few approaches you can use: Append the session value as a query parameter in the URL using PHP: $sessionValue = $_SESSION['session_key']; $url = "../next_page.php?session_value=" . urlencode($sessionValue); In this code, $_SESSION['session_key'] is the

Only Allow Access to Page if Arrived from Assigned

One way to allow access to a page only if the user came from an assigned page is by using PHP sessions. You can set a session variable on the assigned page and then check for that variable on the page you want to restrict access to. If the session variable is not set, you can redirect the user to another page1. For example, on the assigned page you can set a session variable like this:

PHP CURL Openai Remove Quotes from Post Data

Having a hard time getting PHP Curl to work with your post data? I damn near drove me to drinking :) So, you have something like this after using $openaiTemp = $_POST[openaiTemp]; $postData = [ 'model' => $openaiModel, 'prompt' => $openaiModel, 'temperature' => "0.7", 'max_tokens => "2150", 'top_p' => "1", Those pesky double quotes are wrecking the array. There are a couple of ways

Text Based PHP Config File

This is a very simple and basic code that writes config $values to a PHP file via form. Please inspect and get a professional opinion of code before using on a internet facing server as this was written on a localhost server with no internet. This simple HTML (could have .php extension) for the form looks like this: <!DOCTYPE html> <html lang="en"> <head> <meta

Load PDF into PHP File

This code shows using a database but can easily be adopted for direct use. // Database Connection $conn = new mysqli('hostname', 'username', 'password', 'database'); //Check for connection error $select = "SELECT * FROM `infopdf`"; $result = $conn->query($select); while($row = $result->fetch_object()){ $pdf = $row->filename; $path = $row->directory; $date = $row->created_date;

Basic PHP File Cache

cache.php content: class CachingClass { var $cache_time = null; var $file_name = null; function __construct( $file_name, $cache_time = 0 ) { $this->cache_time = ( $cache_time > 0 ) ? $cache_time : (300 * 60); $this->file_name = $file_name; } function startBuffering( ) { ob_start(); } function stopBuffering( ) { $fp = fopen($this->file_name, 'w'); fwrite($fp, ob_get_contents());