php-5.4
PHP built in server and .htaccess mod rewrites
Here’s the router that I use for the builtin php webserver that serves assets from the filesystem if they exist and otherwise performs a rewrite to an index.php file. Run using: php -S localhost:8080 router.php router.php: <?php chdir(__DIR__); $filePath = realpath(ltrim($_SERVER[“REQUEST_URI”], “https://stackoverflow.com/”)); if ($filePath && is_dir($filePath)){ // attempt to find an index file foreach ([‘index.php’, … Read more
How to fix the session_register() deprecated issue?
Don’t use it. The description says: Register one or more global variables with the current session. Two things that came to my mind: Using global variables is not good anyway, find a way to avoid them. You can still set variables with $_SESSION[‘var’] = “value”. See also the warnings from the manual: If you want … Read more
Set port for php artisan.php serve
Laravel 5.8 to 8.0 and above Simply pass it as a paramter: php artisan serve –port=8080 You may also bind to a specific host by: php artisan serve –host=0.0.0.0 –port=8080 Or (for Laravel 6+) you can provide defaults by setting SERVER_PORT and SERVER_HOST in your .env file. You might need to do php artisan cache: … Read more
How do I use PHP to get the current year?
You can use either date or strftime. In this case I’d say it doesn’t matter as a year is a year, no matter what (unless there’s a locale that formats the year differently?) For example: <?php echo date(“Y”); ?> On a side note, when formatting dates in PHP it matters when you want to format … Read more