Blogposts in categorie “Webdev [EN]”

Linux: PHP as a standalone application

Geschreven door Erwin A.W. Maas

Run only PHP in Linux (Ubuntu / Zorin and whatever more...)

Most of my websites don't use a database, therefore I do not need Apache or MySQL to edit them on localhost.
Now I know, you can do that by installing Lamp (Xampp), but easier and quicker is it to just run PHP on it's own (provided that you already have downloaded and unpacked PHP to somewhere in your filesystem).

If you do not yet have PHP installed, here's a quick how-to (1 = check if PHP exists and which version, 4 if no PHP installed, 5 = to check the version again and write the configuration to a file for easier upgrade, 6 = get the last version and 8 = remove old version):

  1. php -v
  2. sudo apt update
  3. sudo apt full-upgrade
  4. sudo apt install php
  5. dpkg -l | grep php | tee packages.txt
  6. sudo add-apt-repository ppa:ondrej/php
  7. sudo apt update
  8. sudo apt autoremove

Now you have PHP installed and you can run it either through the terminal or make a bashfile and add a starter to it on the desktop for convenience. In contrary to what most webresources say, you do not need to move your website-files to a specific default location, just point to them in the bashfile. You basically only need 2 lines to get PHP going.
Open a text-editor or IDE, start with an empty new file and write (editing the path/to-part):
#! /usr/bin/bash
php -S localhost:8080 -t /path/to/my/websites/

Save the file as somename.sh and remember the save-path

Now you only have to create a starter which points to the bash-file and let it run in the terminal (check this option)

Terminal-notifications while running PHP

In the Terminal you should be able to read that PHP has started and while working on your websites the terminal will provide all kinds of useful information about the processes that PHP follows as ordered by the pages that you open in the browser.

In your browser go to localhost:8080 and you'll see your websites. Now you can edit them local in whatever application you wish and upload them to the webserver whenever you are happy to share them 😎

More reasons to use adblockers

Geschreven door Erwin A.W. Maas

Hacked by Youtube

More and more people use browsers with build-in adblockers or browser-extensions for blocking ads.

I just noticed that embedded videos are not only being blocked when you use an adblocker but cause 404-errors for every ad that's on it because the ad-blocker makes the browser refuse these requests, this causes 4 failed pageloads per video, I had two videos and I noticed in a request - tracking script (that I wrote and use) that 8 x googleads (doubleclick etc.) were blocked.

My blog started loading slowly and I tracked down the reason: with every pageload 8 errorpages are being requested as well which causes 9 pageviews on every load instead of just 1.

Click "More" (below) to continue reading

…meer

Values and multidimensional arrays

Geschreven door Erwin A.W. Maas

Full-stack webdev in a nutshell:

When you're trying to get some values from an array that you've been building for hours and you feel you're almost there:

foreach ($all as $allkey => $allvalue) {
    for ($getthefuckingvalues = 0;$getthefuckingvalues < 3;$getthefuckingvalues++) {
        echo $allkey . ": " . $allvalue . "<br>";
    }
}

Didn't work: Warning: Array to string conversion in...😡

Away with external scripts and a strong CSP

Geschreven door Erwin A.W. Maas

Results security scan

I have been busy with a strong Content Security Policy the last couple of months and experienced all kinds of issues with 3rd-party scripts like analytics-tools and a consent-manager script that I needed because of these analytics tools.

To keep everything running fine I had to add several things to the CSP that I didn't like, for example 'unsafe-inline' and 'unsafe-eval'.
Next to that one item of the cookie-consent-script just did not load and there was nothing to do about it before the scriptprovider themselves make changes to it so that I can Hash or Nonce it.

So what did I do?

…meer

Get the real last 24 hours with PHP

Geschreven door Erwin A.W. Maas

Getting the last 24 hours

Looking around on the web about this, you mostly see the wrong solutions, so:
If you want to query a database for the last 24 hours in a MySQL-query like:

SELECT * FROM mytable WHERE date BETWEEN '$lastday' AND '$date'

Then using:

$date = date('Y-m-d'); $lastday = date('Y-m-d',strtotime("-1 day"));

will give you today + yesterday all day.

Instead you need to do:

$lastday = date('Y-m-d',strtotime("-1 day + 24 hours"));

So: if you're not sure, check your code!

From arrays to MySQLi

Geschreven door Erwin A.W. Maas

So: no arrays...

One of my hobbies is genealogy.
My familytree consists of around 12.000 people

I like to host my familytree myself, but I have tried every single application and there's not one that suits me.
So I decided to start building one myself.

On localhost I have been working for about two weeks on an array-based (without a database) application and I got very far, but it came to an abrupt end when the webserver ran out of memory on the most important functionality.

So: that was that and on to a MySQLi-based fully self-build familytree!

The web is going nuts

Geschreven door Erwin A.W. Maas

Back after almost 24hrs.

Well: that was an adventure...

Yesterday morning around 09.00 I couldn't see my webpage anymore and thought it was down. But I also couldn't reach control-panel, no FTP, no Webdisk, nothing.
After 24hrs. I received a message that our IP-number was blocked by the server, blocked by your own domain

Well: Ip whitelisted, problem solved.
That's a bit different than being blocked by Facebook over and over and never receiving an answer to any question... 🙄 🤮 🖕

Free webhost & (sub)Domain

Geschreven door Erwin A.W. Maas

Infinityfree: all that you need.

There used to be a time, especially in the beginning 10-15 years of the internet, that you could build a website for free, practically everywhere.

Not everybody has the money to get a domainname and a hosting-account and then I already hear you saying: get a good webhost! There are no good free webhosts!
I have read those reactions many times and on many websites 🖕

I don't agree, ofcourse there will be limitations, but the quality of your website mainly depends on the sourcecode behind it and there are a variety of ways to deal with whatever situation.

…meer

PHP on localhost made easy

Geschreven door Erwin A.W. Maas

Need only PHP ❓

If you have a website with PHP-files, you can install a webserver-package with PHP, Apache webserver and MySQL. For example: one like Xampp, Wampserver or whatever. This can be a hassle: often you need to change several settings to make everything work.

But what if you only need PHP? Is there an easier way to work on your website offline?

Yes there is, let me explain: you can go to the downloadpage of php.net or if you are on windows even easier: go to the Windows-PHP downloadpage.

…meer

The CSP is ready

Geschreven door Erwin A.W. Maas

That was really an adventure, took me 6 days to make a safe Content Security Policy where all scripts and stylesheets are being loaded

But I learned a lot and it's ready for now (in the future I will try to make more use of nonces instead of hashes)

Means that I can go on with real front-end websitedevelopment, which I love most

CSP: start again after 3 days work

Geschreven door Erwin A.W. Maas

Busy inplementing a strong CSP for the domain: much more work than I expected

Google tagmanager requires a nonce, but that needs mod_unique_id which wasn't installed, but the webhost is very helpful and activated it right away, works fine on Apache-side

Quantcast-choice which generates the cookie-policy application that let's visitors choose to accept or decline, is causing the biggest problem, it breaks the whole website. But now that mod_unique_id is installed I could try use a nonce for that too.

Two of the four scripts are going to use nonces, so why not try that with all the scripts?

So: back to an empty CSP and start all over...