-
Who's Online 2 Members, 0 Anonymous, 427 Guests (See full list)
All Activity
- Today
-
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; }
- Yesterday
-
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);
-
arthur64 joined the community
-
htmcgroup joined the community
- Last week
-
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. -
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
- Earlier
-
Unable to pass variable into function inside array_map()
gizmola replied to ppowell777's topic in PHP Coding Help
The general principles involved in mac_gyver's valuable comments to you, when applied to classes, include the idea of dependency injection (aka "inversion of control"). If you consider your function, what are the dependencies? The first thing to look for would be objects you are creating internally using new keyword. In your code that is this line: $conn = new PDO(DB_CONNECTION_STR, MYSQL_DB_USER, MYSQL_DB_PASSWORD, MYSQL_DB_PDO_OPTIONS); Rather than creating objects inside the function, you should pass them as parameters. Objects and resources are automatically passed by reference, so you are able to use the class inside the function without limitation, including calling methods that mutate the object. Here's a short video that explains Dependency Injection further. While Dependency injection is an OOP specific design pattern, the philosophy can still be applied to your functional code in most cases. You won't have a DI Container, but you can work around that as long as you understand the idea. So to begin to address many of the things brought up by mac_gyver, I'd expect your function signature to look more like this: function calculateResults(PDO $conn, Poll $pollObj, Array &$resultsCalcArray) { // implementation } You are also using the $_SESSION superglobal. A strong argument can be made that you should also pass the superglobal into your function, rather than simply relying on it's superglobal property. Most frameworks have their own session wrapping class, but you could simply use a parameter like $session, and pass $_SESSION into your function. One reason to do that, is that you can then create unit tests for your function, which would not be possible normally, because $_SESSION only exists in the web context and doesn't exist in the CLI environment. So an alternative would be to do this: function calculateResults(PDO $conn, Poll $pollObj, Array &$session, Array &$resultsCalcArray) { // implementation //... at some point $session['total'] = $total; } Here's a small test script you should be sure you understand now and in the future: <?php /* Illustrating PHP Function parameters. */ class o { private $v = 0; public function inc() { $this->v++; } public function getV() { return $this->v; } } function testParams(o $obj) { for ($x=0; $x < 10; $x++) { $obj->inc(); } return $obj->getV(); } function testParams2($fp, $text) { $text = "1." . $text . PHP_EOL; fwrite($fp, $text); } // Pass Array by Reference function testParams3(Array &$globArray) { array_push($globArray, 'grape'); } // Globally scoped variables $globArray = ['apple', 'banana', 'peach']; $obj = new o(); $r = fopen("/tmp/resource.txt", "w+"); $text = "This is some text."; // $retVal = testParams($obj); echo $retVal . PHP_EOL; echo $obj->getV() . PHP_EOL; echo PHP_EOL; echo "text before testParams2: \n"; echo "\t$text" . PHP_EOL; testParams2($r, $text); rewind($r); $fileData = fgets($r, 4096); echo "File Data:\n"; echo "\t$fileData"; echo "text After testParams2::\n"; echo "\t$text" . PHP_EOL; echo PHP_EOL; echo "Array Before testParams3:\n"; var_dump($globArray); echo PHP_EOL; testParams3($globArray); echo "Array After testParams3:\n"; var_dump($globArray); I posted it to 3v4l so you could experiment with it if you choose. -
Unable to pass variable into function inside array_map()
mac_gyver replied to ppowell777's topic in PHP Coding Help
the anonymous function has local variable scope, like any php function. you can add use ($total) to the definition to make the variable available inside the function - $resultsCalcArray = array_map(function($votes) use ($total) { as to the posted code - the input call-time parameter should only be the $id and you should only call this function after you have validated the $id. this function should also have an existing pdo connection as an input call-time parameter. it is the wrong responsibility for this function to make a database connection. there's no point is defining and initializing $conn, $stmt, and $rs. don't use the global keyword to get data into or out of a function. this is not general purpose and results in spaghetti code that is hard to debug problems in. all input data to a function should be supplied as call-time parameters and the function should return the result it produces to the calling code. if you set the default fetch mode to assoc when you make the database connection, you won't need to specify it in each fetch statement. fetchAll() won't ever return a null, so the !is_null() test will never fail and should be removed. since you are only operating on the 'kount' column, that is the only thing the query should SELECT. if you have some reason to select other columns, you can build (or add to) the $resultsCalcArray from just the 'kount' column by using array_column(). you can directly get the total of the $resultsCalcArray 'kount' values by using array_sum(). no in-line code after the throw $e; statement will ever get executed and should be removed. there's generally no point in freeing up result sets, closing prepared query handles, or closing database connections in your code, at all, and there's certainly no point in doing this inside a function, since all those things get destroyed when the function call ends. -
Unable to pass variable into function inside array_map()
Barand replied to ppowell777's topic in PHP Coding Help
To include a variable that is defined externally to the map function you need "use()" $calcArray = [ 34, 56, 82 ]; $total = 10; $calcArray = array_map ( function($v) use ($total) { return round($v / $total); }, $calcArray ); echo '<pre>' . print_r($calcArray, 1) . '</pre>'; Alternatively, you can use this syntax... $calcArray = [ 34, 56, 82 ]; $total = 10; $calcArray = array_map ( fn($v) => round($v / $total), $calcArray ); echo '<pre>' . print_r($calcArray, 1) . '</pre>'; See https://www.php.net/manual/en/functions.arrow.php -
I am getting the exact same error over and over again, and I have no idea why: Consider the code function calculateResults($pollObj) { $conn = null; $stmt = null; $rs = null; $total = 0; global $resultsCalcArray; try { $pollId = stripHTML(cleanXSS($pollObj->id)); $conn = new PDO(DB_CONNECTION_STR, MYSQL_DB_USER, MYSQL_DB_PASSWORD, MYSQL_DB_PDO_OPTIONS); $stmt = $conn->prepare(RESULTS_SQL); $stmt->execute([$pollId, $pollId, $pollId]); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); if (!is_null($rs)) { foreach ($rs as $row) { if (!empty($row['kount'])) { $total += (int) $row['kount']; array_push($resultsCalcArray, $row['kount']); } } } $_SESSION['total'] = $total; if ($total > 0) { // TO PREVENT DIVIDE BY ZERO ERROR $resultsCalcArray = array_map(function($votes) { return round($votes / $total) * 100; }, $resultsCalcArray); } } catch (Exception $e) { $msg = ERROR_MESSAGE . ' calculateResults() ' . date('Y-m-d H:i:s') . ' ' . $e->getMessage(); toLogDB($msg); error_log($msg, 0); throw $e; $hasErrors = true; } finally { if (!is_null($rs)) { $rs = null; } if (!is_null($stmt)) { $stmt = null; } if (!is_null($conn)) { $conn = null; } } } I honestly don't know what I did wrong here, but it is completely failing the entire code within the function inside array_map(), and I have no idea why. Help appreciated and needed. Thanks
-
@LeonLatex This is one of the reasons it is highly advisable that you have scripts that are called via ajax, return json data rather than html markup in most cases. It allows you to separate the data from the markup (which remains in the calling script with the rest of the markup). It also makes it much easier to modify and test your application, as you can focus the php script on returning the data in a structured format that the calling site requires, which can be tested easily with api testing tools like Postman. These days many editors have support for these types of tests through plugins like Thunder client
-
Hi mac_gyver, Thanks again for your help earlier. I just wanted to give you a quick update: the issue is now resolved! As you pointed out, the content in the section was being loaded via AJAX from /ajax/latest_news.php. The problem was that this file was returning unexpected output – specifically, some CSS – instead of the HTML content we intended. To debug it, I added this at the top of latest_news.php: header('Content-Type: text/html; charset=utf-8'); echo '<p>AJAX test: latest_news.php is working</p>'; That confirmed the AJAX request was working and that the file was being loaded correctly. From there, I was able to clean up the file and ensure it returned proper HTML for the frontend to display. Turns out the root cause was that latest_news.php was either misconfigured or returning the wrong content type, which confused the JavaScript handler. Appreciate your guidance – it helped point me in the right direction! Thanks😊🎁👍☕🍪 Best regards, Leon