CORS and htaccess

This works on most all my servers to setup cors: <IfModule mod_headers.c> Header always set Access-Control-Allow-Origin "https://cdpn.io" Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT" Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token" </IfModule> This works on most of

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:

AlmaLinux Manual Install PHP Extensions

AlmaLinux missing extensions installed manually is easy to do. Here's an easy way to manually of install extensions. This example was for aaPanel running AlmaLinux 8. In this example we will install bz2: 1. `cd /www/server/php/82/src/ext/bz2` 2. `/www/server/php/82/bin/phpize` 3. `./configure --with-php-config=/www/server/php/82/bin/php-config` 4. `make` 5. `make test` 6. `make install` As

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

Save and Display DOMPDF

Save PDF file on server and display in users browser: $file_to_save = '/home/stsnew/public_html/pdf/file.pdf'; //save the pdf file on the server file_put_contents($file_to_save, $dompdf->output()); //print the pdf file to the screen for saving header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="file.pdf"'); header('Content-Transfer-Encoding:

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

Using Javascript in PHP Code

Simpe method to use JavaScript inside PHP without all the messy code is a global function: function js_link($src) { //set root path to scripts folder if(file_exists("my/html/root/" . $src)) { //we know it will exists within the HTTP Context return sprintf("<script type="text/javascript" src="%s"></script>",$src); } return "<!-- Unable to load " . $src . "-->"; } Then use: echo

Install wkhtmltopdf & wkhtmltoimage AlmaLinux

Wkhtmltopdf is a powerful open-source command line tool for converting HTML documents into PDF files. It is based on the webkit engine, which is used by many popular browsers such as Safari and Chrome. Wkhtmltopdf can be used to generate high-quality PDFs from HTML documents, and it supports a wide range of features including page headers and footers, page margins, table of contents, and more.