#!/bin/bash
EADDRESS=$([[ "$1" == "" ]] && echo "noreply@example.com" || echo "$1")
EADDRESS=$(echo "$EADDRESS" | sed 's;@;%40;')
RESPONSE=$(
curl "https://heroic.com/wp-admin/admin-ajax.php" \
-H "accept-language: en-US,en;q=0.8" \
-H "accept-encoding: gzip, deflate, br" \
-H "user-agent: Mozilla/5.0 (KHTML, like Gecko) Safari/537.36" \
-H "content-type: application/x-www-form-urlencoded; charset=UTF-8" \
-H "referer: https://heroic.com/email-security/" \
-H "x-requested-with: XMLHttpRequest" \
-H "origin: https://heroic.com" \
-H "authority: heroic.com" \
--data "action=heroic_scan_email" \
--data "data[email]=${EADDRESS}" \
--compressed --silent
)
if command -v php &> /dev/null; then
php -r "print(json_encode(unserialize(urldecode('${RESPONSE}'))));"
fi
PS: Using serialized data is a bad idea: https://www.owasp.org/index.php/PHP_Object_InjectionI primarily write JS for a living but because I freelance I often have to work with wordpress. After spending a few weeks digging into the internals I soon realized that every single wordpress project I've inherited–paid themes included–were horrendous and failed to utilize the most basic facilities provided by core.
In most of these projects a quick turnaround was more important than clean code (probably the cause of the aforementioned horrendous codebases), so I always just hacked away at the templates without every trying to gain a deep understanding of PHP, its recommended best practices, and security gotchas.
My question is, can you point me towards something like "PHP, the good parts"? I would like to know how to write well architected, performant, and secure PHP on the occasions I need to use it professionally. I know that PHP has a reputation as being dangerous by default, so knowing what not to do would be reassuring. So far all of the PHP books I've found have been fairly disappointing; covering all of the features without really detailing any best practices or opinions.
HTTP parsing is notoriously difficult and I'd rather trust cURL (which is battle-tested in a load of environments) than a PHP userspace library.
EADDRESS=$([[ "$1" == "" ]] && echo "noreply@example.com" || echo "$1")
could be replaced with: EADDRESS={$1:-noreply@example.com}
From the man page: ${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.
For: EADDRESS=$(echo "$EADDRESS" | sed 's;@;%40;')
you could use: EADDRESS=${EADDRESS/@/%40}