Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. 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
  3. Today
  4. you are using ajax to load the content into the sections. what you are seeing is whatever /ajax/latest_news.php returns.
  5. Here is a link to the site: Matsnakk so you can se the problem by your self
  6. Hi everyone 👋 I'm running into a strange issue where my CSS styles are being displayed as raw text inside a specific <section> on my site, rather than being properly applied. The affected area is my "Latest News" section, which pulls content dynamically using a PHP foreach loop. Here’s what’s going on: My project structure uses index.php, which includes /inc/main.php. In main.php, I have the section: <section id="latest-news"> <h2>Latest News</h2> <div class="news-thumbnails"> <?php foreach (hentNyheter() as $nyhet): ?> <!-- news card markup --> <?php endforeach; ?> </div> </section> The function hentNyheter() is defined in /db/db.php and returns rows from the news table in MySQL. Each row has columns like id, title, summary, image, published_at. Problem: Instead of rendering styled cards, the CSS itself is being printed as raw text inside the .news-thumbnails area on the front page – almost as if a CSS file was pasted into the page as content. It's appearing in a vertical column inside the section. Things I've confirmed: CSS is loaded via proper <link href="/css/styles.css" rel="stylesheet"> in <head>. I'm not using .css.php files anymore. There is no accidental echo or misplaced <style> inside the HTML section. All variable names used (like $nyhet['title'], $nyhet['summary'], etc.) match the database columns. Function h() is used to escape HTML properly: function h(?string $v): string { return htmlspecialchars((string)$v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } ------- Here is the databasetable: -- MySQL dump 10.13 Distrib 8.0.42, for Win64 (x86_64) -- -- Host: sql11.hmg9.webhuset.no Database: 204088_matsnakk -- ------------------------------------------------------ -- Server version 8.0.36 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!50503 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `news` -- DROP TABLE IF EXISTS `news`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `news` ( `id` int NOT NULL AUTO_INCREMENT, `title` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL, `slug` varchar(220) COLLATE utf8mb4_unicode_ci NOT NULL, `summary` text COLLATE utf8mb4_unicode_ci, `content` mediumtext COLLATE utf8mb4_unicode_ci, `image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `published_at` datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`), KEY `published_at` (`published_at`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `news` -- LOCK TABLES `news` WRITE; /*!40000 ALTER TABLE `news` DISABLE KEYS */; INSERT INTO `news` VALUES (1,'Norsk eplesesong i gang','norsk-eplesesong','Slik bruker du epler i alt fra salater til kaker.','Langt nyhetsinnhold...','news1.jpg','2025-08-06 08:04:35'),(2,'Trend: Fermentering hjemme','fermentering-hjemme','Kimchi og kombucha er i vinden.','Langt nyhetsinnhold...','news2.jpg','2025-08-04 08:04:35'); /*!40000 ALTER TABLE `news` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2025-08-06 18:09:21 ----------------------------------------------- Here is the db.ph database connection: <?php // /db/db.php declare(strict_types=1); $configFile = __DIR__ . '/config.php'; if (is_file($configFile)) { require_once $configFile; } else { // Fallback til miljøvariabler eller feilmelding define('DB_HOST', getenv('DB_HOST') ?: ''); define('DB_NAME', getenv('DB_NAME') ?: ''); define('DB_USER', getenv('DB_USER') ?: ''); define('DB_PASS', getenv('DB_PASS') ?: ''); define('DB_CHARSET', 'utf8mb4'); if (!getenv('DB_HOST')) { die('Mangler /db/config.php. Kjør installasjonen via /install.php.'); } } function db(): PDO { static $pdo = null; if ($pdo instanceof PDO) return $pdo; $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode='STRICT_ALL_TABLES'", ]; try { $pdo = new PDO($dsn, DB_USER, DB_PASS, $options); } catch (PDOException $e) { die('Databasefeil: ' . h($e->getMessage())); } return $pdo; } function hentNyheter(int $limit = 6): array { $pdo = db(); $stmt = $pdo->prepare("SELECT id, title, summary, image, published_at FROM news ORDER BY published_at DESC LIMIT :limit"); $stmt->bindValue(':limit', $limit, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetchAll(); } function h(?string $v): string { return htmlspecialchars((string)$v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } ------ My suspicion is that either: Something is going wrong in how the loop outputs data (possibly empty or malformed values). I'm accidentally printing something unexpected into the HTML (like a full CSS string from the database?) Or perhaps h() is escaping CSS markup that was accidentally inserted into the wrong database column? Has anyone experienced this behavior before, where CSS appears in-page like raw text rather than being interpreted? Let me know if you'd like to see the full files — I can post excerpts from index.php, main.php, and db.php.
  7. this is apparently the previous related thread - https://forums.phpfreaks.com/topic/321226-pdo-error-on-function-since-a-migration-to-pso at that time, the "Statement.php Lines 14-17" were in a file being included before the session_start() and would never have found the session variable set. i'm going to guess that the "fetch() on null error" was occurring on every page request? you have since moved these lines to statement.php. after reviewing the code you posted previously, if this problem is only occurring occasionally, it is likely due to some auto logout logic, a page auto reload occurring exactly at the point of being logged out, and a timing/race condition in the logic, due to all these session variables. at the risk or repeating myself. the only piece of user related data you should store in a session variable upon successful login is the user id (autoincrement primary index.) you should query on each page request to get any other user data, so that any changes made to this other user data take effect on the very next page request. if you cannot determine the cause of this problem, you will need to post all the current code for statemnt.php, everything being included (you should use require for things your code must have) by statement.php, everything those files are including, and index.php (and everything it includes and everything those files include) since it is involved in the redirects and could be redirecting back to statement.php, less any database credentials or sensitive site information (which should be in a configuration .php file), for anyone here to be able to help.
  8. Yesterday
  9. obviously it is not. you must determine what the non-printing value actually is and find where in your code it's being set to that value. you either have an assignment, instead of a comparison, like i already wrote, or you have some code that's running, such as after a redirect, where you didn't stop php code execution, and it's assigning a value that when echoed is an empty value.
  10. On log in depending on the user the session can only be set to 1 of the 4 valuse. Show, Show+, Database or Total. So if it is set it will have one of them. By default it is set to Show. Also it is stable for quite some time before it errors on an auto refresh. Either way it will contain a valid string.
  11. Now that you've confirmed the string is what you expect (I assume), you need to remove that line. Because it's getting in the way of your script outputting valid JSON.
  12. I'm calling PHP from a webpage and I want to pass the resulting JSON back to the webpage with this $jsonString = json_encode($generationResponse); print_r($jsonString); echo $jsonString; According to print_r($jsonString); the json string is '{"code":200,"msg":"success","data":{"taskId":"91a5c1544dba3ceb0c84f9b96300938c"}}' which is OK and valid JSON. But my webpage gives an error Error generating audio: SyntaxError: Unexpected token 'A', "Array ( "... is not valid JSON Can anybody help me with this
  13. $_SESSION['CounterValue'] may be set, but doesn't contain what you think. either use var_dump() on $view to display what it is or use var_export(), with the 2nd parameter set to true, when you supply it to the StoreData() call to cause it's value (empty string '', null, false, or true) to be used. best guess is you have some code assigning a value to it, using one =, instead of testing the value in it using two == or three ===.
  14. Hi, I am still having problems with a web page. I have talked about this before and nobody could help. I have done more research into this. The webpage Statement.php displays a bank statement within certain dates and how this information is to be displayed using a session variable $_SESSION['CounterValue']. This page gets auto refreshed. I very occasionally get a null error on the function. Uncaught Error: Call to a member function fetch() on null Statement.php Lines 14-17: $View = 'Show'; if (isset($_SESSION['CounterValue'])) $View = $_SESSION['CounterValue']; Statement.php Line 131: $stmt = GetAllData($Date,$View); Session variables do time out but the code should default to = 'Show'. I have been capturing the data before calling the function GetAllData() Data table entries 35, '2025-08-01', '1754065485', '86.1.133.80', '2025-07-31-Show', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'N'), (36, '2025-08-01', '1754079812', '86.1.133.80', '2025-07-31-', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'N'), (37, '2025-08-01', '1754079819', '86.1.133.80', '2025-07-31-Show', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36', 'N'), Entry 36 has '2025-07-31 -' the variable is missing in the call to the function GetAllData. Here is the function in a seperate functions file. Function in separate file function GetAllData($StartDate, $View) { StoreData($StartDate ."-" . $View); // *** Store data to trap this error *** $pdo = connectDB(); if($View == 'Show' or $View == 'Show+' ) { $sqlAllData = "SELECT * FROM Bank_Data WHERE EntryDate > ? AND EntryDate <= DATE_ADD(?, INTERVAL 6 WEEK) ORDER BY EntryDate ASC, Output"; $stmt = $pdo->prepare($sqlAllData); $stmt->execute( [ $StartDate, $StartDate] ); return $stmt; } if($View == 'Total' or $View == 'Database' ) { $sqlAllData = "SELECT * FROM Bank_Data ORDER BY EntryDate ASC, Output"; $stmt = $pdo->prepare($sqlAllData); $stmt->execute(); return $stmt; } } Can anyone find out what is happening to my ($_SESSION['CounterValue'] and why is it not defaulting to $View = 'Show' This is driving me mad now as it has been going on ever since I upgrades this to PDO last year.
  15. Last week
  16. I figured someone would yell at me for that. I did that for testing purposes to make it faster. I will see about why the Lets Encrypt CA is not trusted. So the following is true? 50-client.conf - should have the client cert 50-server.conf - should have the server cert My PHP Application in class/Database.php - should have the same cert in 50-client.conf ?
  17. Right, so the error is telling you that the CA is untrusted. Aside from that, you should not be using the same cert for the client and the server. You need to generate a client cert for the client, and the CN's for each cert should be different. The MySQL manual has a walk through of process: https://dev.mysql.com/doc/refman/5.7/en/creating-ssl-files-using-openssl.html
  18. I am uaing mariadb 11
  19. I am attempting to create a connection to my database that I have set up with SSL. It is saying "Cannot make a connection to the database" The error in the apache log is as follows: [Sun Aug 03 02:27:59.418655 2025] [php:notice] [pid 176919] [client 71.244.230.195:62660] Database Connection Failed: SQLSTATE[HY000] [2006] MySQL server has gone away The error in mysql log is as follws: 2025-08-03 2:27:59 8 [Warning] Aborted connection 8 to db: 'unconnected' user: 'unauthenticated' host: 'web2.dataguy2020.com' (This connection closed normally without authentication) I have created a .env file that has information as follows: APP APP_NAME=MyApp APP_ENV=dev COMMUNITY_NAME="Community Name" CONTACT_EMAIL="[email protected]" CONTACT_PHONE="555-555-5555" #Database DB_HOST="domain.to.sqlhost.com" DB_PORT=3306 DB_NAME="databseName" DB_USER="username" DB_PASS="password" #Database Connection Certs DB_CA="/path/to/cacert.pem" DB_CERT="/path/to/cert.pem" DB_CERT_KEY="/path/to/key.pem" My classes/Database class is as follows: <?php require __DIR__ . "/../vendor/autoload.php"; use Dotenv\Dotenv; class Database { private PDO $pdo; public function __construct() { $parentDirectory = dirname(__DIR__); $dotenv = Dotenv::createImmutable($parentDirectory, '.env'); $dotenv->load(); // echo "<pre>"; // Use <pre> for formatted output in a browser //foreach ($_ENV as $key => $value) { // echo "$key = $value\n"; //} //echo "</pre>"; $dbHost = $_ENV['DB_HOST']; $dbName = $_ENV['DB_NAME']; $dbUser = $_ENV['DB_USER']; $dbPass = $_ENV['DB_PASS']; $dbca = $_ENV['DB_CA']; $dbcert = $_ENV['DB_CERT']; $dbkey = $_ENV['DB_CERT_KEY']; $dsn = "mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4"; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, // SSL/TLS options PDO::MYSQL_ATTR_SSL_CA => $dbca, // Path to CA certificate PDO::MYSQL_ATTR_SSL_CERT => $dbcert, // Path to client certificate (if required) PDO::MYSQL_ATTR_SSL_KEY => $dbkey, // Path to client key (if required) PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false // Verify server's SSL certificate ]; try { $this->pdo = new PDO($dsn, $dbUser, $dbPass, $options); //$this->pdo = new PDO($dsn, $this->username, $this->password, $options); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch(PDOException $e) { //Handle connection errors error_log("Database Connection Failed: " . $e->getMessage()); die("Could not connect to the database."); } //end of catch } //end of function public function getConnection(): PDO { return $this->pdo; } } //end of class At the bottom of my index.php I have the following as I am using this as a test <?php include_once ('classes/Database.php'); $db = new Database(); $pdo = $db->getConnection(); if ($pdo) { echo "Database Connection was successful"; } else { echo "Database Connection has failed"; } ?> What shows up in the browser is "Database Connection has failed" In /etc/mysql/mariadb.conf.d I have configured both the server the client. They are both using the same certificates as they are connection from the same server for now. I am looking at expanding the number of database hosts. The 50-client.conf has the following information [client] # Example of client certificate usage ssl-cert = /path/to/cacert.pem ssl-key = /path/to/key.pem ssl_cert = /path/to/cert.pem ssl-cipher=ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256 tls_version = TLSv1.2 The 50-server.conf contains the following information ssl_ca = /etc/mysql/ssl/chain.pem ssl_cert = /etc/mysql/ssl/cert.pem ssl_key = /etc/mysql/ssl/privkey.pem require-secure-transport = on #ssl_cipher="DHE-RSA-AES128-GCM-SHA256:AES128-SHA" ssl_cipher="ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384" tls_version = TLSv1.2,TLSv1.3 When I attempt to run the following error I get the following error: mysql -h localhost -u #username --ssl-cert=/path/to/cert.pem --ssl-key=/path/to/key.pem --ssl-ca=/path/to/cacert.pem ERROR 2026 (HY000): TLS/SSL error: tlsv1 alert unknown ca Other key things to know is that I created these certs with certbot. I am not sure if that is what is the cause of these errors or not. I am doing the following ssl_cert = cert.pem that is generated ssl_ca = fullchain.pem that is generated ssl_key = privkey.pem that is generated Any assistance would be great!
  20. Hell, Considering ... $imap = your connection to your imap server & E-Mail account etc . //$status = imap_setflag_full($imap , "1", "\SEEN" ); Sets as READ // $status = imap_clearflag_full($imap , "1", "\Seen" ); // SETS as UN Read echo gettype($status) . "\n"; echo $status . "\n"; imap_close($imap);
  21. Hello, I found it :~) :~) PHP had a Hidden function :~/ = imap_clearflag_full() That Works :~) Marks as READ :~) BRILL :~) Ta Sid
  22. Hello, I have been looking at this for 2 days now :~( Can anyone help ? I have a script that gets messages from my imap account and runs through them to get uids :~) BUT I need to Mark some as READ I have found imap_setflag_full() which uses \\SEEN as a Flag to set read, but I need to set Unread ! google etc says remove \\SEEN to set Unread BUT that does Not work ! Am I doing something wrong ? Can you suggest ? Thank-You Sid
  23. I'm sorry for the incredibly long delay in replying to these, but I just wanted to say a big thank you for all your help. Have got it working now!
  24. This is a problem you will encounter when you have code in production and need to update it. You'll need some way to "cache bust" files that users have already cached locally or they will continue to use the old version. For development, if you develop using Chrome, you can install an extension. I have used this one for a long time and it is safe and reliable: https://chromewebstore.google.com/detail/clear-cache/cppjkneekbjaeellbfkmgnhonkkjfpdn Make sure you set it up to pin the button to the extension window, and then when you need to test, you can click it will clear cached items for the site you are working on.
  25. Paul-D: I've redacted a few things in your post as a courtesy but you can safely assume it's already out there on the internet. Be more careful in the future. Shame about the email addresses too.
  26. I'd suggest changing your MySQL password now that you've posted it in a forum
  27. Thanks. I need single quotes around ':ThisDate' working fine now. Thanks again.
  28. Named arguments need to be quoted. An example from: https://www.php.net/manual/en/pdostatement.execute.php $sth->execute( array( ':calories' => $calories, ':colour' => $colour ) ); "Unexpected" colons in the middle of PHP code gives it indigestion. Regards, Phill Ward.
  29. Hi I have an error on a web page Parse error: syntax error, unexpected token ":", expecting "]" in /vhost/r/e/d/redacted/www/secure/SecurePDO.php on line 256 The Code page with all the relevant functions is this. This worked before I converted from my_sql to PDO. Have checked this over and it seems to comply. function StoreData($Page) at the very end of the file. Thanks for any help. x
  1. Load more activity
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.