-
Who's Online 1 Member, 1 Anonymous, 359 Guests (See full list)
All Activity
- Today
-
Beyond mac's insights and salient comments, the code snippet you provided tells us nothing, as it is not the code you are using. The only way to gain insight into this is having detailed logging to review when the mailer freezes. I'd also suggest scanning the release notes in regards to the phpMailer releases, to check if there are any Breaking changes you might have missed, or things that are now handled differently between the two versions. There are 2 likely possibilities based on your comments: There are some emails that are causing issues when delivered. The way the code is written (and the environment involved) uses up available resources (network connections, database handles, or other available memory). Many companies use phpMailer so I am doubtful that there is an issue with it that would be trivially obvious, but regardless of that, you need detailed debugging which will be best facilitated by the injection of an object that implements PSR3 as described in the phpMailer source code here. If you don't already have that, here's a bit more on setting that up: After the instantiation of the PHPMailer object, that would involve a call like this: $mail->Debugoutput = new myPsr3Logger; A lot of projects use the well regarded monolog library which allows for logging to be integrated into many different logging systems, but in your case, just insuring it is writing to a log file on your system would be sufficient. As for some trivia, the author of monolog is the same guy who created PHP's dependency management tool Composer. The documentation states that the only log level that will be used is the 'Debug' level.
-
JamesHycle joined the community
-
It is the scripts in the subdirectory named boatlettering. There are 2 I see being called: The image src runs boatNamePreviewImage-new.php load_image2.php gets called when changes to the parameters are made. Obviously things on the server changed and this is probably because your code uses an ancient and long end of life version: php5.6. On top of that, it relies on the imagemagick library, so any issues with the version of imagemagik that supported that old version of php will also cause it to no longer function. I don't see this as being a quick fix, and there is very little people here could do for you, even with the source code, as your existing code is antiquated, and needs to be updated to run under supported versions of php and the imagemagick library, as well as running on a supported operating system, which it most likely did not previously, or now that it has been updated, will no longer support the old code.
-
What you will see if you open that PHP file in a text editor such as Notepad.
-
Need help with PHP and ImageMagick problem
GMann1984 replied to GMann1984's topic in PHP Coding Help
What is the "source code"? -
We can't help unless you share the source code of the script. All I could say at this point is the script outputs a 0 byte image.
-
I have a boat name designer that uses ImageMagick to generate the image. It has been working fine for years and then suddenly stopped working this morning. When I clicked on the link, instead of the designer I got a "500 server error". I contacted the Host provider and they were able to get the designer back online but the image preview did not work. Here is our communication from oldest to newest: ================================================= The website has a form that should generate an image, but it fails to do so, everything else works except for that particular component. The customer wanted to revert to a backup, but it did not work. Opened the ticket to take a deeper look. ================================================= After investigating the issue, we were not able to find the root cause of the Image preview issue. At first, there was an issue with the suPHP module as it was not installed on the shared host. I had to edit a line of code in the `.htaccess` file so the 500 error you called for went away. Adding a `#` to every line of the block so it was disabled: ``` # #suPHP_ConfigPath /home/boatlett/public_html/boatlettering/ # # #order allow,deny #deny from all # ``` Before that, I also installed the module to prevent any code modifications. This created issues on the server overall, so I had to revert to the previous setting. The logs are not giving us any explicit cause of the issue. So the best option will be to contact a developer so they have a better solution to the issue with the form, as it looks like it should run with PHP 5.6, according to this line: ``` AddType application/x-httpd-ea-php56 .php .php5 .phtml ``` ================================================= Unfortunately there are no errors being displayed, so we would have nothing to work off of in reviewing the 'BoatLetteringPreviewForm.php' script. No errors are shown when checking the F12 developer console, and no errors are being logged in the site's home directory. In such a case, you would need to contact the script's developer to determine why the script is not functioning properly. If the script requires some specific PHP version or extension, we could set the site to use it, though we would not be able to determine the script's requirements simply by looking at it. ================================================= At this point I suggested they reinstall the ImageMagick module as I recalled this issue happened a few times in the past and was fixed rather quickly by doing that. Here is their reply: ================================================= I checked the module and tried to reinstall, but I do not think it will take any effect. I did found old similar tickets for the same problem and noticed we also suggested a developer to look into the same issue further. (But reinstalling fixed the issue so no need to contact a developer) You can try to change the PHP version and see how it goes, but a developer would be indeed more suited to check the issues here. ================================================= It seems to me they don't want to reinstall ImageMagick because they don't think it will do any good. Should I push them on the matter? If nothing more than to eliminate it as a cause? I was hoping someone could take a look at the page: https://www.boatlettering.net/boatlettering/BoatLetteringPreviewForm.php and give me an idea of what's going on and why the image generation portion would suddenly stop working without making any changes to it? Sincerely,
-
GMann1984 joined the community
- Yesterday
-
ZenitJal joined the community
-
sunrisemumbai joined the community
-
That was the question originally posed as I interpreted it. This is why the OP posted interest in the ESP32, which is a line of 32 bit Microcontrollers. They are typically used for IOT projects, and I don't think are a good match for this. A Raspberry pi, Orange Pi, or even a GMTek Mini PC are all a lot more viable given the OP's professed direction in this project, involving an OS capable of running an HTTP server and app server.
-
AI tools are usually pretty good for getting started with a simple task like this. I googled the relay board you mentioned and found a PDF that lists the data required to turn the relays on or off. I feed that into ChatGPT and asked it to describe the protocol to get an understanding of it. I then asked it to generate a web form using PHP that can be used to turn the relays on or off. <?php // relay_control.php // === Function to build command === function relayCommand(int $relay, bool $state): string { $header = 0xA0; $relayByte = $relay & 0xFF; $stateByte = $state ? 0x01 : 0x00; $checksum = ($header + $relayByte + $stateByte) & 0xFF; return pack('C4', $header, $relayByte, $stateByte, $checksum); } // === Handle form submission === $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $relay = intval($_POST['relay'] ?? 1); $state = ($_POST['action'] === 'on'); $cmd = relayCommand($relay, $state); $hexCmd = strtoupper(bin2hex($cmd)); // Example: write to USB device (uncomment when you know the device path) // $fp = fopen('/dev/ttyUSB0', 'wb'); // if ($fp) { // fwrite($fp, $cmd); // fclose($fp); // } $message = "Relay $relay " . ($state ? 'ON' : 'OFF') . " → Command: $hexCmd"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Relay Control</title> <style> body { font-family: Arial, sans-serif; padding: 20px; } form { margin: 20px 0; } select, button { font-size: 16px; padding: 5px 10px; margin: 5px; } .msg { margin-top: 15px; font-weight: bold; } </style> </head> <body> <h1>LCUS-8 Relay Control</h1> <form method="post"> <label for="relay">Relay number:</label> <select name="relay" id="relay"> <?php for ($i = 1; $i <= 8; $i++): ?> <option value="<?= $i ?>"><?= $i ?></option> <?php endfor; ?> </select> <button type="submit" name="action" value="on">Turn ON</button> <button type="submit" name="action" value="off">Turn OFF</button> </form> <?php if ($message): ?> <div class="msg"><?= htmlspecialchars($message) ?></div> <?php endif; ?> </body> </html> Sounds like a project that you could do with a raspberry pi computer + the relay board. Might be able to go even simpler if you didn't need to host the control interface on the device itself and instead just communicated with it over the network or a serial port.
- Last week
-
how are you invoking this? is the code looping over data, and if so what is the code with the looping? approximately how long was the execution time for each of the segments of sent emails? you are using exceptions for errors. when using exceptions, none of the discrete error checking logic will ever get executed upon an error and should be removed. when using exceptions for errors, unless you are doing something special with the error information, you should not catch and handle exceptions in your code. instead let php catch and handle any exception, where php will use its error related settings (error_reporting, display_errors, and log_errors) to control what happens with the actual error information, via an uncaught exception error. php's error_reporting should always be set to E_ALL. if you are invoking this via a browser, you should set display_errors to ON, so that any php detected errors (which will include any uncaught exceptions) will be displayed. if you are invoking this via a cron job/scheduled task, you should set log_errors to ON, so that any php detected errors will be logged.
-
I just updated PHPMailer from version 5.1 to 6.10.0. I was successfully sending small batches of emails today, so I thought everything was great. Tonight I went to run a job that was going to send a couple thousand emails out and it stopped about a third of the way through. It just stopped sending out emails after about 369 emails. I started it again from the point where it quit and it only made it through the next 500ish. After starting from that spot it made it through the list. There are no errors messages, no error logs, no debugging logs. I never had anything like this happen when running v5.1. Nothing else changed in my code, data files, etc. So I am wondering if there is some limiting factor with the newer PHPMailer? Does it take more memory? I'm looking for ideas on how to debug this. Any relevant differences between PHPMailer 5.1 and 6.10.0? Suggestions how I should debug it? Other than the first 4 lines of code below, nothing has changed. I find it hard to believe it is a code issue since this has been running for many years without issue. Ideas where I should start? require_once 'include_files/PHPMailer/PHPMailer_v6.10.0/PHPMailer/Exception.php'; require_once 'include_files/PHPMailer/PHPMailer_v6.10.0/PHPMailer/PHPMailer.php'; require_once 'include_files/PHPMailer/PHPMailer_v6.10.0/PHPMailer/SMTP.php'; $mailer = new PHPMailer\PHPMailer\PHPMailer(true); $mailer -> IsSMTP(); $mailer -> Host = 'smtp.mandrillapp.com'; $mailer -> SMTPAuth = true; $mailer -> Username = 'myusername'; $mailer -> Password = 'mypassword'; $mailer -> SMTPSecure = 'tls'; $mailer -> Port = 587; $mailer -> IsHTML(true); $mailer -> AddReplyTo('My Email'); $mailer -> FromName = "My Name"; $mailer -> From = 'My Email'; $mailer -> AddAddress('Your Email'); $mailer -> Subject = 'My Subject'; $mailer -> Body = 'My Message'; if ($mailer -> Send()) { } else { print "Mailer Error: " . $mailer->ErrorInfo; }
-
Did I miss where a question was asked? What was the source .py being copied here, in case that's necessary information? Input arguments are rather awkward, like gizmola said something like $_POST or even $_GET will probably be more appropriate. Obviously the exact nature of the $on/$off stuff is irrelevant to operating the board so it can be rewritten into any style. For the board, seems odd that you're actually supposed to include a "0x" in the buffer? Otherwise since this is a device, a mere file_put_contents is likely sufficient - w vs. r+ shouldn't matter.
-
The script does no parameter count checking, which isn't a great idea. First thing you would want to do is check $argc == 3. I'm assuming you know that $argv[0] is the script name, so typically you would check the count and display a "usage {$argv[0]} relay# 0|1 [off|on]\n", or something similar if it's not the right count. With that said you stated you wanted to do this with an html page, so probably it would be better to just have a "self posting" form script where you use html to display the controls, and set the 2 parameters based on whatever UI decisions you make. In that case, you would want to get the 2 parameters via the $_POST[] superglobal array, perhaps with html form elements named $_POST['relay'] and $_POST['state'] which you can set to be 0 or 1. You certainly in either case want to do some bounds checking (cast to int or use intval) and insure that the relay is in the range of 0-7. It would also be good if there was a way to determine the pre-existing state of the system. With that said, given the circumscribed set of functions, and purpose of this, I would suggest that you consider the alternative of a board based controller, perhaps with an lcd keypad. With a "mini-pc" you have all the issues of how your web app is going to be displayed, although if your device has wifi, you could design the html/css to be responsive, and control it using a pc or phone. Sounds like a fun and interesting project.
-
I'm starting a new project to replace the $700 hot tub controller board with a "Roll your own". Haven't decided on the CPU - ESP32-? or a less than $100 micro pc. As needed the relay board ( LCUS-8 USB Relay Module 8 Channel DC 5V ) will drive T9AS1D12 30A relays. Web page for display and control. Anyhow looking for how to control the relay board using PHP - Google wasn't any help. I found a 70+ line python script ( I dislike py ) so I used it as a base for a 19 line PHP script. #!/usr/bin/php <?php $on = array ("", "\xa0\x01\x01\xa2", "\xa0\x02\x01\xa3", "\xa0\x03\x01\xa4", "\xa0\x04\x01\xa5", "\xa0\x05\x01\xa6", "\xa0\x06\x01\xa7", "\xa0\x07\x01\xa8", "\xa0\x08\x01\xa9"); $off = array ("", "\xa0\x01\x00\xa1", "\xa0\x02\x00\xa2", "\xa0\x03\x00\xa3", "\xa0\x04\x00\xa4", "\xa0\x05\x00\xa5", "\xa0\x06\x00\xa6", "\xa0\x07\x00\xa7", "\xa0\x08\x00\xa8"); $relay = $argv[1]; $oo = $argv[2]; $fd = fopen ("/dev/ttyUSB0", "r+"); switch ($oo) { case 0: fprintf ($fd, "0x%s", $off[$relay]); break; case 1: fprintf ($fd, "0x%s", $on[$relay]); break; } fclose ($fd);
-
Uncaught Error: Value of type null is not callable
gizmola replied to ppowell777's topic in PHP Coding Help
Looking at your code, you should consider the application of DRY (Don't repeat yourself). The entire switch statement, is literally the same code in every case, other than the field name. global $erroredIDArray; global $erroredIDIndexArray; $elem = ''; switch ($i) { case 0: // FIRST NAME $elem = (array_key_exists('firstName', $_POST) && isset($_POST['firstName']) && !is_null($_POST['firstName'])) ? $_POST['firstName'] : ''; if (!is_null($elem) || !$isValidName($elem)) { $isValid = false; array_push($erroredIDArray, 'firstName'); array_push($erroredIDIndexArray, $i); } break; You're also using globals, which you should avoid here. I don't understand what the purpose of the numeric case #'s is, but it's also quite likely you don't need that at all if you create a function to handle this code. I left it out, as it seems to be duplicative. Just mechanically breaking your code out into a function would get you this: function isValid($key, array &$erroredIDArray) { $elem = ''; $elem = (array_key_exists($key, $_POST) && isset($_POST[$key]) && !is_null($_POST[$key])) ? $_POST[$key] : ''; if (!is_null($elem) || !$isValidName($elem)) { array_push($erroredIDArray, $key); // array_push($erroredIDIndexArray, $i); return false; } return true; } -
It wasn't from the browser; it came from tokencheck.php itself due to an error accidentally resetting the value of $_SESSION['token'], which has been resolved
-
are you getting an error from the browser about redirecting (it would be a http xxx error number) or is this your - ' Illegal redirection from ...' message? note: require is not a function. the () around the path/filename do nothing and should be removed.
-
Uncaught Error: Value of type null is not callable
mac_gyver replied to ppowell777's topic in PHP Coding Help
this is unnecessary and is hiding simple typo mistakes. except for unchecked checkbox/radio fields, all other fields will be set/will exist after a form has been submitted. after you have detected that a post method form has been submitted, these 'always set' fields will be set, regardless of what they contain. you only need check if a field is set for checkbox/radio fields. your post method form processing code should - detect if a post method form was submitted - if($_SERVER['REQUEST_METHOD'] === 'POST'). detect if there is $_POST (or $_FILES) data. there may not be if the total size of the submitted form data is greater than the post_max_size setting. keep the form data as a set in a php array variable, then operate on elements in this array variable throughout the rest of the code. trim all the input data, mainly so that you can detect if all white-space characters were entered. validate all inputs separately, storing user/validation errors in an array using the field name as the array index. after the end of the validation logic, if there are no errors (the array holding the user/validation errors is empty), use the submitted form data. after using the form data, if there are no errors, redirect to the exact same URL of the current page to cause a get request for that page. this will prevent the browser from trying to resubmit the form data should that page get browsed back to or reloaded. if you want to dynamically validate and process form data, and dynamically produce the corresponding form, create an array with the expected form fields, using the field name as the array index, with an array for each field with a label element, field data type, validation rules, and processing rules. you can then loop over this defining array and call general-purpose code to handle each field. -
I am getting an Illegal Redirection error trying to redirect to an absolutely valid URL. I can't seem to fix this problem, and I know that there is no whitespace causing this issue to fail. <?php if (!array_key_exists('token', $_SESSION) || !isset($_POST['token']) || is_null($_POST['token']) || $_SESSION['token'] !== $_POST['token']) { $msg = ERROR_MESSAGE . ' tokencheck.php ' . date('Y-m-d H:i:s') . ' Illegal redirection from "' . $_SERVER['HTTP_REFERER'] . '"'; toLogDB($msg); error_log($msg); header('Location: ' . ERROR_FULL_URL); die(); } ?> <?php ini_set('session.gc_maxlifetime', 60 * 10); session_start(); require('./globals/constants.php'); require('./globals/functions.php'); require('./globals/crypto.php'); require('./feedback/includes/constants.php'); require('./feedback/includes/globals.php'); require('./feedback/includes/functions.php'); require('./feedback/includes/delivery.php'); require('./feedback/includes/validation.php'); require('./feedback/includes/tokencheck.php'); // REST OF THE CODE ?>
-
Uncaught Error: Value of type null is not callable
ppowell777 replied to ppowell777's topic in PHP Coding Help
Sigh. Way too easy and I completely missed it -
Uncaught Error: Value of type null is not callable
Barand replied to ppowell777's topic in PHP Coding Help
if (!is_null($elem) || !$isValidName($elem)) { ^ ??? -
I have no idea why I am getting this error, but I am constantly getting this error when I am trying to do a default set onto $elem based on whether or not $_POST['firstName'] exists or not. Error: Code: $elem = (array_key_exists('firstName', $_POST) && isset($_POST['firstName']) && !is_null($_POST['firstName'])) ? $_POST['firstName'] : ''; if (!is_null($elem) || !$isValidName($elem)) { $isValid = false; array_push($erroredIDArray, 'firstName'); array_push($erroredIDIndexArray, $i); } Entire function: function isValidByCase($isValid, $i) { global $erroredIDArray; global $erroredIDIndexArray; $elem = ''; switch ($i) { case 0: // FIRST NAME $elem = (array_key_exists('firstName', $_POST) && isset($_POST['firstName']) && !is_null($_POST['firstName'])) ? $_POST['firstName'] : ''; if (!is_null($elem) || !$isValidName($elem)) { $isValid = false; array_push($erroredIDArray, 'firstName'); array_push($erroredIDIndexArray, $i); } break; case 1: // LAST NAME $elem = (array_key_exists('lastName', $_POST) && isset($_POST['lastName']) && !is_null($_POST['lastName'])) ? $_POST['lastName'] : ''; if (is_null($elem) || !$isValidName($elem)) { $isValid = false; array_push($erroredIDArray, 'lastName'); array_push($erroredIDIndexArray, $i); } break; case 2: // EMAIL $elem = (array_key_exists('email', $_POST) && isset($_POST['email']) && !is_null($_POST['email'])) ? $_POST['email'] : ''; if (!is_null($elem) || strlen(trim($elem) === 0 || strlen(trim($elem)) > EMAIL_MAX_LENGTH || !$isValidEmail($elem))) { $isValid = false; array_push($erroredIDArray, 'email'); array_push($erroredIDIndexArray, $i); } break; case 3: // SUBJECT $elem = (array_key_exists('subject', $_POST) && isset($_POST['subject']) && !is_null($_POST['subject'])) ? $_POST['subject'] : ''; if (!is_null($elem) || !is_numeric($elem) || !isValidSubject($elem)) { $isValid = false; array_push($erroredIDArray, 'subject'); array_push($erroredIDIndexArray, $i); } break; case 4: // QUESTION $elem = (array_key_exists('question', $_POST) && isset($_POST['question']) && !is_null($_POST['question'])) ? $_POST['question'] : ''; if (!is_null($elem) || !isValidQuestion($elem)) { $isValid = false; array_push($erroredIDArray, 'question'); array_push($erroredIDIndexArray, $i); } break; default: break; } return $isValid; } I am checking for everything I can think of: 1) Is the key in $_POST? 2) Is $_POST[key] set? 3) Is $elem null? 4) Does $elem pass the sniff test in every single individual function which nominally checks for null + emptiness? I don't know what else to do, and the error is persistent. Please help Thanks
-
How to use libsodium encryption/decryption in PHP 8.3+ and IIS 10+
maxxd replied to ppowell777's topic in PHP Coding Help
Totally unsolicited advice here but if you have to choice to move off IIS with php, I highly recommend doing so. While it's true that php can run on IIS, unless MS has made some massive changes since the last time I tried it there are so many tiny little hoops like this you're gonna have to jump through that it's likely to end up counter-productive. Ubuntu server is free, the download is easy to install and maintain, and it's support of php (while admittedly not always the most up-to-date) is quite good. - Earlier
-
Solved it; I used too old of a version of encryption/decryption, and the solution was simpler than I thought: <?php /** * Using most recent versions of PHP Sodium functions for PHP 8.3.8. Remember to do the following when requiring this file: * * <b> * require('./globals/constants.php'); * require('./globals/functions.php'); * require('./globals/crypto.php'); * </b> */ function decrypt($encText, $nonce, $key) { try { if (empty($encText) || empty($nonce) || empty($key)) { throw new Exception('You must provide text, a nonce, and a key'); } return sodium_crypto_secretbox_open($encText, $nonce, $key); } catch (Exception $e) { $msg = ERROR_MESSAGE . ' hasSecCode() ' . date('Y-m-d H:i:s') . ' ' . $e->getMessage(); toLogDB($msg); error_log($msg, 0); throw $e; } } function encrypt($text, $nonce, $key) { try { if (empty($text) || empty($nonce) || empty($key)) { throw new Exception('You must provide text, a nonce, and a key'); } return sodium_crypto_secretbox($text, $nonce, $key); } catch (Exception $e) { $msg = ERROR_MESSAGE . ' hasSecCode() ' . date('Y-m-d H:i:s') . ' ' . $e->getMessage(); toLogDB($msg); error_log($msg, 0); throw $e; } } /** * Wrapper for {@see sodium_crypto_secretbox_keygen} */ function getKey() { try { return sodium_crypto_secretbox_keygen(); } catch (Exception $e) { $msg = ERROR_MESSAGE . ' hasSecCode() ' . date('Y-m-d H:i:s') . ' ' . $e->getMessage(); toLogDB($msg); error_log($msg, 0); throw $e; } } /** * Wrapper for {@see random_bytes} */ function getNonce() { try { return random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); } catch (Exception $e) { $msg = ERROR_MESSAGE . ' hasSecCode() ' . date('Y-m-d H:i:s') . ' ' . $e->getMessage(); toLogDB($msg); error_log($msg, 0); throw $e; } } ?> <?php require('./globals/constants.php'); require('./globals/functions.php'); require('./globals/crypto.php'); $key = getKey(); $str = 'Lorem ipsum dolor sit amet. The quick brown fox jumped over the lazy dog. Lorem ipsum dolor sit amet'; $nonce = getNonce(); $encStr = encrypt($str, $nonce, $key); $decStr = decrypt($encStr, $nonce, $key); if ($decStr === false) { echo ' was not decrypted<br />'; } ?> <!DOCTYPE html> <html> <head> <title>Blah</title> </head> <body> <p> Original string: <?php echo $str ?><br /><br /> Encrypted string: <?php echo $encStr ?><br /><br /> Decrypted string: <?php echo $decStr ?><br /><br /> </p> </body> </html>
-
I am trying to learn how to use encryption and decryption using the built-in libsodium.dll module I have for PHP 8.3.8 and IIS 10+, however, I am unable to get it to work; I am getting this error: Here is the code: <?php // PECL libsodium 0.2.1 and newer /** * Found at <a href="https://stackoverflow.com/questions/3422759/php-aes-encrypt-decrypt"> * https://stackoverflow.com/questions/3422759/php-aes-encrypt-decrypt</a> */ /** * Encrypt a message * * @param string $message - message to encrypt * @param string $key - encryption key * @return string */ function safeEncrypt($message, $key) { $nonce = \Sodium\randombytes_buf( \Sodium\CRYPTO_SECRETBOX_NONCEBYTES ); return base64_encode( $nonce. \Sodium\crypto_secretbox( $message, $nonce, $key ) ); } /** * Decrypt a message * * @param string $encrypted - message encrypted with safeEncrypt() * @param string $key - encryption key * @return string */ function safeDecrypt($encrypted, $key) { $decoded = base64_decode($encrypted); $nonce = mb_substr($decoded, 0, \Sodium\CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); $ciphertext = mb_substr($decoded, \Sodium\CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); return \Sodium\crypto_secretbox_open( $ciphertext, $nonce, $key ); } ?> <?php require('./globals/crypto.php'); $key = \Sodium\random_bytes(\Sodium\CRYPTO_SECRETBOX_KEYBYTES); $str = 'Lorem ipsum dolor sit amet. The quick brown fox jumped over the lazy dog. Lorem ipsum dolor sit amet'; $encStr = safeEncrypt($str, $key); $decStr = safeDecrypt($encStr, $key); ?> <!DOCTYPE html> <html> <head> <title>Blah</title> </head> <body> <p> Original string: <?php echo $str ?><br /><br /> Encrypted string: <?php echo $encStr ?><br /><br /> Decrypted string: <?php echo $decStr ?><br /><br /> </p> </body> </html> What else should I be doing to ensure encryption and decryption works? Thanks