PHP

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search
>Though maybe you were looking for PPH or PPP?
This is actually... helpful?

You can read this for more info about the topic

Who looks like this or than me?

PHP is a general-purpose scripting language especially suited to web development. Its syntax is similar to Java and Perl and was originally created by Canadian programmer Rasmus Lerdorf in 1993 as a set of Common Gateway Interface (CGI) binaries written in C for tracking visits to his online resume. Over time, PHP evolved into a powerful server-side scripting language that now powers millions of websites, such as soyjak.party and even this very wiki. Even though it is sometimes seen as “old” or “messy” compared to newer frameworks and languages, PHP still sees heavy use so don’t believe what the angry Chud programmers on Twitter or Reddit say. In fact, PHP still gets plenty of feature updates making it still just as good with other competitive server-side languages. Its ease of deployment, gigantic ecosystem of frameworks and libraries, and the sheer number of legacy PHP sites still online ensure that PHP will be around for a long time to come.

Notable features[edit | edit source]

PHP mascot as elephant jak.

PHP is best known for:

  • PHP code runs on the server and generates HTML to be sent to the client’s browser. This makes it ideal for building websites, content management systems, and web applications.
  • PHP has an massive library of frameworks, plugins, and tools thanks to it's wide adoption and ecosystem from platforms such as ACK!press.
  • PHP can be mixed directly with HTML code, making it beginner-friendly and great for creating templates.
  • PHP works seamlessly with SQL systems, such as MySQL, PostgreSQL, SQLite, and other databases to create dynamic, data-driven websites.
  • PHP runs on Windows, Linux, macOS, and most web servers, making it highly versatile.
  • By using the declare(strict_types=1) directive, PHP can enforce strict types and type information.

How does PHP work?[edit | edit source]

At the heart of PHP is the Zend Engine, a open-source compiler and runtime environment for the PHP scripting language. Whenever a PHP file is requested, the following happens behind the scenes:

  1. The PHP interpreter lexes the PHP code, then converts it into an internal representation called an abstract syntax tree.
  2. The Zend Engine then compiles the syntax tree into low-level opcodes, which are a simplified set of instructions optimized for execution.
  3. The Zend Engine executes the opcodes line by line, handling function calls, database queries, file I/O, and any other server-side logic.
  4. The result of the script (usually HTML, JSON, or another format) is sent back to the web server, which delivers it to the client’s browser.

Scripts[edit | edit source]

Scripts
Menu
CSS switcher
css.php

include this in the <head> of your php script.

<?php
if (!isset($_COOKIE['theme'])) {
    setcookie("theme", "yotsuba", time() + (86400 * 399), "/");
} else {
    $theme = $_COOKIE['theme'];
}
if ($theme == "light") {
    echo("<link href='/soychiver/base.css' rel='stylesheet'>");
} else if ($theme == "dark") {
    echo("<link href='/soychiver/base.css' rel='stylesheet'>");
    echo("<link href='/soychiver/dark.css' rel='stylesheet'>");
}

theme.php

This is where the user chooses their theme.

<?php
function setTheme($theme) {
    setcookie("theme", $theme, time() + (86400 * 399), "/");
    header("Location: index.php");
    exit;
}
$themearray = ['light', 'dark'];

if (isset($_GET['a']) && in_array($_GET['a'], $themearray)) {
    setTheme($_GET['a']);
} else {
    die("Available themes: <a href='?a=light'>Light</a> <a href='?a=dark'>Dark</a>");
}
Textboard
This is a simple way of how an imageboard works.
  1. You go to the server, and fetch "index.html".
  2. You enter your shit thread / reppey in the post form, and send it off; usually to imgboard.php
  3. The server submits your thread into the database and regenerates index.html with the new thread in it

The reason that the post index doesn't generate on the fly (e.g. with index.php) is because:

  1. That would use more processing power than needed
  2. It's an anonymous imageboard, there are no user-specific algorithms.

The code itself

This is a textboard because I can't be asked to make an imageboard in php. You can change it all you like, freely, if you want. It's based of Gazou BBS (Yotsuba, OpenYotsuba and Vichan both originated from this script if that matters)


<?php
// DO NOT USE THIS IN PRODUCTION, currently you can't post but nophono cares
// These are constants: variables that don't change
define("PHP_SELF", "imgboard.php"); // This file
define("PHP_SELF2", "index.html"); // The index file
$log = "imglog.log"; // The post log file
$title = "North Textboard"; // Your board title
// The log should look like:
// 1|01-01-2025|Subject|Name|Body
// 2|02-01-2025|Another post|North|sdfasdfasgdfafgs
$poststring = file_get_contents($log); // Gets contents of the log
$postlist1 = explode("\n", $poststring); // Creates a 1 dimensional array of all cells in the log

// No more comments here on out! It should be obvious doe.

$dat="<html><head><title>$title</title></head>
<body bgcolor=#ffffee text=#800>
<p align=right>
[<a href='".PHP_SELF."'>Rebuild Index</a>]
</p>
<p align=center>
<font color=#800000 face='MS PGothic' size=5>
<b><SPAN>$title</SPAN></b><br></font></p><hr>";
foreach ($postlist1 as $post2) {
    $post = explode("|", $post2);
    $dat.='<small>No.'.$post[0].'</small> <big><font color=#FF0000>'.$post[2].'</font></big><br>
<small>Name <font color=#117743>'.$post[3].'</font> Date '.$post[1].'</small><blockquote>';
    $dat.=$post[4].'</blockquote></td></tr></table><hr>';
}
$dat.='<p align=center><small>Based off <a href="http://php.loglog.jp/">GazouBBS</a>, made by <a href="https://soyjakwiki.org/User:North"</a>North</a></small></body></html>';
file_put_contents(PHP_SELF2, $dat); // Puts $dat into the index file
header('Content-Type: text/plain'); // Nophono
header("Location: " . PHP_SELF2); // Redirects user 2 index
echo("Regenerating index..."); // Nophono
?>


PHP is part of a series on Computer Science.

Languages Low Level AssemblyCC++C#Holy CRust

High Level JavaGoPHPPythonSQL BashJavaScriptPowerShellActionScriptScratchRuby

Markup HTMLCSSSVG
Software Imageboards QuotechanVichanYotsubaOpenYotsuba

OSes WindowsLinuxAndroidTempleOS

Other BabybotMcChallengeSystemdMS PaintJS PaintPhotoshopFlash
More SoyGNUCGIDDoSVibe codingGame developmentPiracyRegexDoxingMicrosoftAppleGoogleDataminingWebPArtificial soyduelRatio duelingCustomizationRicingFSLWindows debloating