Laravel Sanctum Email Verification Not Updating email_verified_at Field

I’m building an API using Laravel 10 with Sanctum for authentication, and I’m encountering an issue with email verification. After the user clicks the verification link, the email_verified_at field remains null.

This is my register component

import React from "react";
import { useNavigate } from "react-router-dom";

function Register() {
  const [name, setName] = React.useState("");
  const [email, setEmail] = React.useState("");
  const [password, setPassword] = React.useState("");
  const navigate = useNavigate();

  React.useEffect(() => {
    if (localStorage.getItem("token")) {
      navigate("/account");
      window.location.reload();
    }
  }, []);

  async function register() {
    const item = { name, email, password };

    let result = await fetch("http://localhost:8000/api/register", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
      },
      body: JSON.stringify(item),
    });

    const data = await result.json();

    if (result.ok) {
      alert("Please verify your email before logging in.");
      navigate("/login");
    } else {
      alert(data.message || "Error registering.");
    }
  }

  return (
    <div className="py-16">
      <div className="flex items-center flex-col justify-center gap-6">
        <div className="flex items-center justify-center">
          <h1>Register Form</h1>
        </div>

        <div className="flex items-center flex-col gap-5 justify-center">
          <input
            type="text"
            placeholder="Name"
            value={name}
            onChange={(e) => setName(e.target.value)}
          />
          <input
            type="email"
            placeholder="Email"
            value={email}
            onChange={(e) => setEmail(e.target.value)}
          />
          <input
            type="password"
            placeholder="Password"
            value={password}
            onChange={(e) => setPassword(e.target.value)}
          />
        </div>

        <div>
          <button onClick={register} className="border-2 border-black p-2">
            Register
          </button>
        </div>
      </div>
    </div>
  );
}

export default Register;

This is my auth controller

<?php

namespace AppHttpControllers;
use IlluminateValidationValidationException; //manually imported
use IlluminateSupportFacadesHash; //manually imported
use IlluminateHttpRequest;
use AppModelsUser; //manualy imported
use IlluminateAuthEventsVerified;
use IlluminateFoundationAuthEmailVerificationRequest;
use CarbonCarbon;
class AuthController extends Controller
{
    //

    public function verifyEmail(Request $request, $id, $hash)
    {
        $user = User::find($id);

        if (!$user) {
            return response()->json(['message' => 'User not found.'], 404);
        }


        if (!hash_equals(sha1($user->getEmailForVerification()), $hash)) {
            return response()->json(['message' => 'Invalid verification link.'], 400);
        }


        if ($user->email_verified_at) {
            return response()->json(['message' => 'Email already verified.']);
        }

        $user->email_verified_at = Carbon::now();
        $user->save();

        return response()->json(['message' => 'Email verified successfully.']);
    }
    public function resendEmailVerification(Request $request)
    {
        if ($request->user()->hasVerifiedEmail()) {
            return response()->json(['message' => 'Email already verified.']);
        }

        $request->user()->sendEmailVerificationNotification();

        return response()->json(['message' => 'Verification email sent.']);
    }

    public function register(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|unique:users',
            'password' => 'required|string|min:6'
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password)
        ]);


        $user->sendEmailVerificationNotification();



        $token = $user->createToken('auth_token')->plainTextToken;

        return response()->json(['token' => $token, 'user' => $user], 201);
    }

    public function login(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required'
        ]);

        $user = User::where('email', $request->email)->first();

        if (!$user || !Hash::check($request->password, $user->password)) {
            return ["error" => "Invalid credentials"];
        }

        $token = $user->createToken('auth_token')->plainTextToken;

        return response()->json(['token' => $token, 'user' => $user]);
    }

    public function logout(Request $request)
    {
        $request->user()->tokens()->delete();

        return response()->json(['message' => 'Logged out']);
    }

    public function user(Request $request)
    {
        return response()->json($request->user());
    }



}

These are my api routes

<?php

use AppHttpControllersAuthController;
use AppHttpControllersDisplayController;
use AppHttpControllersOrderController;
use AppHttpControllersStripeController;
use IlluminateHttpRequest;
use IlluminateSupportFacadesRoute;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});


Route::post("/login",[AuthController::class,"login"]);
Route::post("/register",[AuthController::class,"register"]);

Route::middleware('auth:sanctum')->post('/addOrder', [OrderController::class, 'addOrder']);

Route::middleware('auth:sanctum')->post('/pay', [StripeController::class, 'pay']);

Route::middleware('auth:sanctum')->get('/displayOrders', [DisplayController::class, 'displayOrders']);



Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verifyEmail'])
    ->middleware(['signed']) 
    ->name('verification.verify');

And these are my web routes

<?php

use IlluminateSupportFacadesRoute;
use IlluminateFoundationAuthEmailVerificationRequest;
use AppHttpControllersAuthController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('/login', function () {
    return redirect('http://localhost:5173/login');
})->name('login');
Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verifyEmail'])
    ->middleware(['auth:sanctum', 'signed'])
    ->name('verification.verify');

I already made sure that the user model has the email verification thing enabled. Simply , after I receive the confirmation email on mailtrap and click the button I am getting redirected to the login page and then when checking the data base the “email_verified_at” entry is still empty… pls help

Is t possible to listen to multiple connections with ReactPHP truly async?

I need to start tcp server that accepts connections and for every connection creates websocket connection to another server, receives data from tcp, processes the data and sends it to WS

Data sent to tcp is being send continuously, so without truly async handling both tcp and ws, I have lost packets

I tried using reactphp/child-process, still child process needs to liste to stdin and WS, so the problem is the same

Im not proficient in reactPHP, am I doing something wrong or is it just impossible with this environment ?

Page name ‘Login’ is not working on WordPress

I have created a new page called Login (mysite.com/login) on my wordpress website but when I tried to access the page, it throws an error

This is all I see in the source

<html>
<head>
<meta name="color-scheme" content="light dark">
<meta charset="utf-8">
</head>
<body>
<pre>{"error":"not found"}</pre>
<div class="json-formatter-container"></div>
</body>
</html>

I tried disabling and enabling the plugins and nothing worked.

Any help would be appreciated.

Autoupgrade prestashop 1.7.8.8 to 8.1.7 – how to solve error with “upgradeDB” step?

I try to upgrade Prestashop from 1.7.8.8 to 8.1.7. I decided to use autoupgrade via cli option. I got an error (I have many more but finally resolved them but stuck here):

INFO - 506 files left to upgrade.
INFO - === Step upgradeFiles
INFO - 106 files left to upgrade.
INFO - === Step upgradeFiles
INFO - All files upgraded. Now upgrading database...
INFO - Restart requested. Please run the following command to continue your upgrade:
INFO - $ modules/autoupgrade/cli-upgrade.php --dir=admin9254z9q7u --action=upgradeDb --data=eyJlcnJvciI6bnVsbCwic3RlcERvbmUiOmZhbHNlLCJuZXh0IjoidXBncmFkZUZpbGVzIiwic3RhdHVzIjoib2siLCJuZXh0X2Rlc2MiOiJJTkZPIC0gUmVzdGFydCByZXF1ZXN0ZWQuIFBsZWFzZSBydW4gdGhlIGZvbGxvd2luZyBjb21tYW5kIHRvIGNvbnRpbnVlIHlvdXIgdXBncmFkZTpcbiIsIm5leHRRdWlja0luZm8iOltdLCJuZXh0RXJyb3JzIjpbXSwibmV4dFBhcmFtcyI6eyJvcmlnaW5WZXJzaW9uIjoiMS43LjguOCIsIml [..]
INFO - === Step upgradeDb
INFO - Cleaning file cache
INFO - Running opcache_reset
PrestaShopException in /var/www/presta_us_klon/classes/db/Db.php line 303
#0 /var/www/presta_us_klon/classes/db/Db.php(236): DbCore::getClass()
#1 /var/www/presta_us_klon/config/alias.php(47): DbCore::getInstance()
#2 /var/www/presta_us_klon/classes/shop/Shop.php(1351): pSQL()
#3 /var/www/presta_us_klon/classes/shop/Shop.php(351): ShopCore::findShopByHost()
#4 /var/www/presta_us_klon/config/config.inc.php(117): ShopCore::initialize()
#5 /var/www/presta_us_klon/modules/autoupgrade/classes/UpgradeContainer.php(665): require_once('...')
#6 /var/www/presta_us_klon/modules/autoupgrade/classes/Task/AbstractTask.php(165): PrestaShopModuleAutoUpgradeUpgradeContainer->initPrestaShopCore()
#7 /var/www/presta_us_klon/modules/autoupgrade/classes/Task/Upgrade/UpgradeDb.php(90): PrestaShopModuleAutoUpgradeTaskAbstractTask->init()
#8 /var/www/presta_us_klon/modules/autoupgrade/classes/Task/Runner/ChainedTasks.php(59): PrestaShopModuleAutoUpgradeTaskUpgradeUpgradeDb->init()
#9 /var/www/presta_us_klon/modules/autoupgrade/cli-upgrade.php(50): PrestaShopModuleAutoUpgradeTaskRunnerChainedTasks->run()
#10 {main}

which is related with this class

    public static function getClass()
    {
        $class = '';
        if (PHP_VERSION_ID >= 50200 && extension_loaded('pdo_mysql')) {
            $class = 'DbPDO';
        } elseif (extension_loaded('mysqli')) {
            $class = 'DbMySQLi';
        }

        if (empty($class)) {
            throw new PrestaShopException('Cannot select any valid SQL engine.');
        }

        return $class;
    }

but as you can see I have both php7.4 extensions:

root@joffrey:/var/www# php7.4 -m | grep pdo_mysql
pdo_mysql
root@joffrey:/var/www# php7.4 -m | grep mysqli
mysqli
root@joffrey:/var/www/presta_us_klon# cat testy.php
<?php
print_r(get_loaded_extensions());
?>
root@joffrey:/var/www/presta_us_klon# php7.4 testy.php | grep -i 'mysqli|pdo_mysql'
    [33] => mysqli
    [34] => pdo_mysql

Problem using define() to enable debug mode

On Prestashop, I have a production and staging server. I want to activate debug mode on staging environment.

I can use $_SERVER['SERVER_NAME'] to identify my environment, so I can define my constant like this :

if (! defined('_PS_MODE_DEV_')) {
    define('_PS_MODE_DEV_', $_SERVER['SERVER_NAME'] === 'staging.domain.name');
}

But it’s not working, the debug mode is not enabled.

When I’m testing my values :

var_dump(! defined('_PS_MODE_DEV_')); // true
if (! defined('_PS_MODE_DEV_')) {
    var_dump($_SERVER['SERVER_NAME'] === 'staging.domain.name'); // true
    define('_PS_MODE_DEV_', $_SERVER['SERVER_NAME'] === 'staging.domain.name');
}
var_dump(_PS_MODE_DEV_); // true

Everything looks good, I don’t understand why the debug mode stills disabled.

I thought it was a problem with the mode itself, but if I set like this :

if (! defined('_PS_MODE_DEV_')) {
    define('_PS_MODE_DEV_', true);
}

It works, the debug mode is enabled…

Maybe there is some limitation with define() ? (I cannot find an example using an expression).

So, I tried like this :

if (! defined('_PS_MODE_DEV_')) {
    if ($_SERVER['SERVER_NAME'] === 'staging.domain.name') {
        define('_PS_MODE_DEV_', true);
    }
    else {
        define('_PS_MODE_DEV_', false);
    }
}

That works too, the debug mode is enabled on staging. HOWEVER, the debug mode is enabled on production too !

I am completely lost, because if I set even like this :

if (! defined('_PS_MODE_DEV_')) {
    if (false) {
        define('_PS_MODE_DEV_', true);
    }
    else {
        define('_PS_MODE_DEV_', false);
    }
}

The debug mode stills enabled… I have no idea what is going on here. For me, it looks like PHP ignores my condition, and takes always the first define().

Could someone give me some ideas to understand what happens here ?

Why a login page using password_verify doesn’t work? [duplicate]

The admin page should be accessed by entering the ‘admin’ NIC and password. The patient sites for other NICs should be accessible with their password.

Here is the patient(user) table:

id NIC Password Name Phone Address
1 admin 1234 Ben 0118675456 Colombo
2 00236584V abcd1 Ann 0114253963 Dehiwela

I used NIC as primary key in the table
here is my PHP code .

<?php
session_start();
$NIC="";
$password = "";
$error = "";
if($_SERVER['REQUEST_METHOD']=='POST')
{
    $NIC = $_POST['nic'];
    $password = $_POST['password'];
    if(empty($NIC)||empty($password))
    {
        $error = "Email and Password are required !";
    }
    else
    {
        include "database.php";
        $dbConnection = getDatabaseConnection();
        
        $statement = $dbConnection->prepare("SELECT id, NIC, Password, Name, Phone, Address FROM user WHERE NIC = ?");
        
        $statement->bind_param('s',$NIC);
        $statement->execute();
        $statement->bind_result($id, $nic, $stored_password, $Name, $Phone, $Address);
        if($statement->fetch())
        {
            if(password_verify($password,$stored_password))
            {
                if(strtolower($NIC)==="admin")
                {
                    $_SESSION["admin_id"] = $id;
                    $_SESSION["admin_username"] = $nic;                 
                    header("location: admin-dashboard.php");
                    exit;
                }
                else
                {
                    $_SESSION["id"]=$id;
                    $_SESSION["nic"]=$nic;
                    $_SESSION["Name"]=$Name;
                    $_SESSION["Password"]=$password;
                    $_SESSION["Phone"]=$Phone;
                    $_SESSION["Address"]=$Address; 
                    
                    header("location: patient-profile.php");
                    exit;
                }
            }
            else
            {
                $error="Email or Password invalid";
            }
        }
        else
        {
            $error="Email or Password invalid";
        }
        $statement->close();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login / Signup - Wintan Hospital</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <img src="IMG/Logo.jpg" width="100px" height="100px" alt=""/><br>
        <h1>Wintan Hospital </h1>
    </header>

    <main>
        <section class="auth-section">
            <div class="login-form">
                <h2>Login</h2>
                <form action="patient-login.php" method="post">
                    <strong><?= htmlspecialchars($error) ?></strong>
                    <label for="username">Username/NIC:</label>
                    <input type="text" id="nic" name="nic" value="<?= htmlspecialchars($NIC) ?>">
                    <label for="password">Password:</label>
                    <input type="password" id="password" name="password">
                    <button type="submit">Login</button>
                    <a href="forgot-password.html">Forgot Password?</a>
                </form>
            </div>
        </section>
    </main>

    <footer>
        <p>&copy; 2024 Wintan Hospital. All rights reserved.</p>
    </footer>
</body>
</html>

Insert data using php to html textarea in mustache template [closed]

I read multi-line data using php from a database which has been previously validated on insertion. To create an editable form I’m using a Mustache template containing html form data with data inserted from php. SFSG with standard form elements (text, number).

However I’m not having success with trying to insert the data into a textarea with:

<div>
  <label col-sm-2" for="description">Article description:</label>
  <br>
  <textarea  name="description" rows="8" cols="45" <?php echo {{adescription}}; ?></textarea>
</div> 

Where adescription is the data item holding the text read from the database.

What I would like to achieve is that text is editable in the textarea so I can have the user edit it and then I’d check it and put it back in the database again.

WordPress Plugin development – React integration is not working

I am developing a wordpress Plugin and during development, I decided to continue the code with react, instead of Html. In order to do that I needed to build the React environment on WordPress. I have built it and it was compiling correctly. Thereby my goal was to see if react was also rendering on the wordpress page, but on the wordpress settings page of my Plugin was nothing to see from the react test component.

The expected result is that the contents of the react file renders on the settings page. For this task I got help from the WordPress Documentation. I would be very happy if any of you can help me to solve this bug.

Here is how I did the enque on the php file(the whole contents of the php file):
Look at the functions justinLegalRegisterTestPage, justinLegalRenderTestPage, justinLegalEnqueueTestPageScripts which are relevant for the react component.

<?php

/**
 * Justin Legal Plugin – Admin Settings
 *
 * This file adds the Justin Legal settings page to the admin, registers common settings
 * (including AJAX handlers), and renders the settings page with tabs by including
 * tab-specific files.
 *
 * @package JustinLegalPlugin
 */


// Prevent direct access.
if (! defined('ABSPATH')) {
    exit;
}

// Always include the tab files so that their registration functions run.
require_once plugin_dir_path(__FILE__) . 'settings/main-settings-tab.php';
require_once plugin_dir_path(__FILE__) . 'settings/compliance-tab.php';

/**
 * Add the Justin Legal settings page to the admin menu.
 */
function justinLegalAddSettingsPage()
{
    add_menu_page(
        'Justin Legal Settings',           // Page title.
        'Justin Legal',                    // Menu title.
        'manage_options',                  // Capability.
        'justin-legal-settings',           // Menu slug.
        'justinLegalRenderSettingsPage',   // Callback function.
        'dashicons-admin-generic',         // Icon.
        100                                // Position.
    );
}
add_action('admin_menu', 'justinLegalAddSettingsPage');


/**
 * Render the settings page with tabs.
 * The URL remains unchanged (no query parameters are appended) because the tab switching
 * is handled via JavaScript.
 */
function justinLegalRenderSettingsPage()
{
?>
    <div class="wrap">
        <h1>Justin Legal Settings</h1>
        <h2 class="nav-tab-wrapper">
            <a href="#" class="nav-tab nav-tab-active" data-tab="main">Main Settings</a>
            <a href="#" class="nav-tab" data-tab="compliance">Compliance</a>
        </h2>

        <div id="tab-main">
            <?php justinLegalRenderMainSettingsTab(); ?>
        </div>
        <div id="tab-compliance" style="display: none;">
            <?php justinLegalRenderCompliance(); ?>
        </div>
    </div>
<?php
}

/**
 * AJAX handler to retrieve profile data from the external API.
 */
function justinLegalGetProfileData()
{
    if (! current_user_can('manage_options')) {
        wp_send_json_error('Permission denied');
    }

    $options = get_option('justin_legal_settings');
    $encodedId = '';
    if (isset($_POST['lawfirm']) && ! empty($_POST['lawfirm'])) {
        $encodedId = sanitize_text_field($_POST['lawfirm']);
    } else {
        $encodedId = isset($options['lawfirm']) && ! empty($options['lawfirm']) ? $options['lawfirm'] : 'sFuCvloJ';
    }

    $apiUrl = 'https://justin-api-dev.azurewebsites.net/api/v1/LawFirm/encoded/' . urlencode($encodedId);
    $response = wp_remote_get($apiUrl);
    if (is_wp_error($response)) {
        wp_send_json_error($response->get_error_message());
    }
    $code = wp_remote_retrieve_response_code($response);
    $body = wp_remote_retrieve_body($response);
    if ($code != 200) {
        wp_send_json_error('API returned HTTP code ' . $code . ': ' . $body);
    }
    $data = json_decode($body, true);
    if (empty($data) || ! is_array($data)) {
        wp_send_json_error('Empty data returned from API');
    }
    $kanzleiName = isset($data['name']) ? sanitize_text_field($data['name']) : '';
    $options['kanzlei_name_customer'] = $kanzleiName;

    update_option('justin_legal_settings', $options);
    wp_send_json_success(array('kanzlei_name' => $kanzleiName));
}
add_action('wp_ajax_justin_legal_get_profile_data', 'justinLegalGetProfileData');

/**
 * Enqueue admin scripts on the Justin Legal settings page.
 */
function justinLegalAdminScripts($hook)
{
    if ($hook !== 'toplevel_page_justin-legal-settings') {
        return;
    }
    wp_enqueue_script(
        'justin-legal-admin-js',
        plugin_dir_url(__FILE__) . 'js/admin.js',
        array('jquery'),
        filemtime(plugin_dir_path(__FILE__) . 'js/admin.js'),
        true
    );
}
add_action('admin_enqueue_scripts', 'justinLegalAdminScripts');


/**
 * Enqueue the Justin Legal widget CSS in WP Admin
 */
function justinLegalEnqueueWidgetCSS($hook)
{
    if ($hook === 'toplevel_page_justin-legal-settings') {
        wp_enqueue_style(
            'justin-legal-widget-css',
            'https://widgets.justin-legal.com/index.css',
            array(), // without array() it will not work
            null
        );
    }

    wp_enqueue_style(
        'justin-legal-admin-overrides',
        plugin_dir_url(__FILE__) . 'css/admin.css',
        array('justin-legal-widget-css'),
        filemtime(plugin_dir_path(__FILE__) . 'css/admin.css')
    );
}
add_action('admin_enqueue_scripts', 'justinLegalEnqueueWidgetCSS');


// Register the Test Page as a Subpage under the Justin Legal settings page.
function justinLegalRegisterTestPage()
{
    add_submenu_page(
        'justin-legal-settings',             // Correct parent slug (matches your add_menu_page slug)
        __('Test Page', 'justin-legal'),     // Page title
        __('Test Page', 'justin-legal'),     // Menu title
        'manage_options',                    // Capability required
        'test-page',                         // Menu slug
        'justinLegalRenderTestPage'          // Callback to render the page
    );
}
add_action('admin_menu', 'justinLegalRegisterTestPage');

function justinLegalRenderTestPage()
{
    printf(
        '<div class="wrap" id="justin-legal-test-page">%s</div>',
        esc_html__('Loading…', 'justin-legal')
    );
}


function justinLegalEnqueueTestPageScripts($hook)
{
    if ($hook !== 'justin-legal-settings_page_test-page') {
        return;
    }

    $asset_file = plugin_dir_path(__FILE__) . 'build/index.asset.php';
    if (! file_exists($asset_file)) {
        wp_die('The asset file for the Test Page does not exist. Run `npm run build` to create it.');
    }
    $asset = include $asset_file;

    wp_enqueue_script(
        'justin-legal-admin-script',
        plugin_dir_url(__FILE__) . 'build/index.js',
        $asset['dependencies'],
        $asset['version'],
        array(
            'in_footer' => true,
        )
    );

    wp_localize_script(
        'justin-legal-admin-script',
        'justinLegalData',
        array(
            'nonce' => wp_create_nonce('justin_legal_nonce'),
            'ajaxUrl' => admin_url('admin-ajax.php')
        )
    );
}
add_action('admin_enqueue_scripts', 'justinLegalEnqueueTestPageScripts');

And here is the src/index.jsx:

import domReady from "@wordpress/dom-ready";
import { createRoot } from "@wordpress/element";

const SettingsPage = () => {
  return <div>Placeholder for settings page</div>;
};

domReady(() => {
  const container = document.getElementById("justin-legal-test-page");

  if (container) {
    const root = createRoot(container);
    root.render(<SettingsPage />);
  } else {
    console.error("Container #justin-legal-test-page not found");
  }
});

On the browser page, I don’t see any error. When I run npm run build:

asset index.js 587 bytes [emitted] [minimized] (name: index)
asset index.asset.php 133 bytes [emitted] (name: index)
Entrypoint index 720 bytes = index.js 587 bytes index.asset.php 133 bytes
orphan modules 126 bytes [orphan] 3 modules
runtime modules 663 bytes 3 modules
./src/index.js + 3 modules 674 bytes [not cacheable] [built] [code generated]
webpack 5.98.0 compiled successfully in 1398 ms

And when I run npm run start:

> [email protected] start
> wp-scripts start

asset index.js 5.26 KiB [emitted] (name: index) 1 related asset
asset index.asset.php 133 bytes [emitted] (name: index)
Entrypoint index 5.39 KiB (3.75 KiB) = index.js 5.26 KiB index.asset.php 133 bytes 1 auxiliary asset
runtime modules 937 bytes 4 modules
built modules 674 bytes [built]
  ./src/index.js 548 bytes [built] [code generated]
  external ["wp","domReady"] 42 bytes [built] [code generated]
  external ["wp","element"] 42 bytes [built] [code generated]
  external "ReactJSXRuntime" 42 bytes [built] [code generated]
webpack 5.98.0 compiled successfully in 343 ms
asset index.js 5.26 KiB [emitted] (name: index) 1 related asset
asset index.asset.php 133 bytes [emitted] (name: index)
Entrypoint index 5.39 KiB (3.75 KiB) = index.js 5.26 KiB index.asset.php 133 bytes 1 auxiliary asset
runtime modules 937 bytes 4 modules
cached modules 126 bytes [cached] 3 modules
./src/index.js 548 bytes [built] [code generated]

How to Implement Pagination with API Using PHP [closed]

I’m working with the Clinical Trials API to retrieve study data using PHP. Currently, I can pull through the first 10 results as thats the default, but I’m struggling to implement pagination to access the remaining records.

I’ve tried using PHP sessions to handle the nextPageToken for pagination, but I’m having trouble utilizing the token properly. Ideally, I want to load more results incrementally (e.g 10 at a time) without fetching all the data at once, because it obviously causes my site to time out.

Here’s my code I’m currently working with


defined('ABSPATH') || exit;

// Enqueue custom CSS
function register_custom_styles() {
    wp_enqueue_style('custom-shortcode-style', get_template_directory_uri() . '/style.css', [], '1.0.0');
}
add_action('wp_enqueue_scripts', 'register_custom_styles');

// Register shortcode
add_shortcode('external_data', 'fetch_clinical_trials');

function fetch_clinical_trials($atts) {
    if (is_admin()) {
        return '<p>Shortcode [external_data] preview.</p>';
    }

    $atts = shortcode_atts(['title' => 'Clinical Trials Data'], $atts, 'external_data');

    $response = wp_remote_get('https://clinicaltrials.gov/api/v2/studies');
    if (is_wp_error($response)) {
        return 'Error fetching data.';
    }

    $studies = json_decode(wp_remote_retrieve_body($response), true)['studies'] ?? [];

    $html = '<h2>' . esc_html($atts['title']) . '</h2>';
    $html .= '<table>
                <tr><th>NCT ID</th><th>Organization</th><th>Title</th><th>Status</th><th>Start Date</th><th>Completion Date</th><th>Sponsor</th></tr>';

    foreach ($studies as $study) {
        $html .= '<tr>';
        $html .= '<td>' . esc_html($study['protocolSection']['identificationModule']['nctId'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['identificationModule']['organization']['fullName'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['identificationModule']['briefTitle'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['statusModule']['overallStatus'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['statusModule']['startDateStruct']['date'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['statusModule']['primaryCompletionDateStruct']['date'] ?? 'N/A') . '</td>';
        $html .= '<td>' . esc_html($study['protocolSection']['sponsorCollaboratorsModule']['leadSponsor']['name'] ?? 'N/A') . '</td>';
        $html .= '</tr>';
    }

    $html .= '</table>';
    return $html;
}

I understand there’s a nextPageToken for pagination, but I can’t figure out how to correctly use it to fetch subsequent results. How can I implement a proper pagination mechanism for this scenario?

Any advice or examples on how to properly handle this token for paginated requests would be greatly appreciated! Thank you !

Nextcloud error not logged in the server log [closed]

I’m migrating a Nextcloud server to another Rocky Linux server. At first I got this error in the browser:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

And found it in the data/nextcloud.log:

Failed to connect to the database: An exception occurred in the driver: could not find driver

Then I installed the missing driver but still I have an error but now there is nothing in the server log.

Already searched in /var/log/httpd and /var/log/php-fpm/

How to debug?

I solved the problem by installing missing php modules. But still the question about the log persists.

Laravel 11 – how to call the old ‘Handler.php’ class from app.php – withExceptions

I have recently created a new project in Laravel 11 and can not get my custom error handling class to work. I have a class I use throughout all my Larvael projects (laravel 10). I want to use this class in Laravel 11 to process all my errors, but it seems the new version relies on the withExceptions method in app.php

->withExceptions(function (Exceptions $exceptions) {

Does anyone know how I can get the withExceptions class to still use this (or any) external class for handling


use IlluminateFoundationExceptionsHandler as ExceptionHandler;

class Handler extends ExceptionHandler {

}

Laminas Mail with SMTP not sending mail on development server (but does send on production server)

There is a lot on the web, but i didn’t solve it yet.

I am using laminas mail with an SMTP connection to send mail, this works fine on production server, but for testing purposed i also want to use it on my developmentserver. For some reason it does not work there, with the same settings (see below)

$options   = new SmtpOptions(array(
                'name'              => 'maintenanceplus.nl',
                'host'              => 'mail.antagonist.nl',
                'port'              => 587,
                'connection_class'  => 'login',
                'connection_config' => array(
                    'username' => '****',
                    'password' => '****',
                    'ssl' => 'tls'
                ),
            ));

I am using Apache2 with PHP8.2 on a windows machine.

How do I split queues in Symfony Messenger?

Could you please explain why, when launching the indexing process using the command $this->bus->dispatch(new ProductIndexMessage($productIds)) (with hundreds of such commands being executed at once), they are evenly distributed across all transports and queues? According to the design, they should only be launched on the searchIndex queue.

PHP: 8.4.5, Symfony 7.2

/usr/local/bin/php -f /var/www/html/app/bin/console messenger:stats
 ---------------- -------
  Transport        Count  
 ---------------- -------
  async            40     
  searchIndex      40     
  genImageThumbs   40     
  failed           6      
 ---------------- -------

File:

<?php

declare(strict_types=1);

namespace AppMessageSearch;

use AppMessageSearchIndexMessageInterface;
use AppUtilsUtils;

final readonly class ProductIndexMessage implements SearchIndexMessageInterface
{
    /**
     * @var int[]
     */
    public array $productIds;

    public function __construct(int|array $productIds)
    {
        $this->productIds = Utils::asPosAndNotZeroNotDupIntegerArray($productIds);
    }
}

There is a configured messanger.yaml:

framework:
    messenger:
        failure_transport: failed

        transports:
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%/async'
                retry_strategy:
                    max_retries: 20
                    multiplier: 2

            searchIndex:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%/searchIndex'
                options:
                    exchange:
                        name: 'searchIndex'
                retry_strategy:
                    max_retries: 20
                    multiplier: 2

            genImageThumbs:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%/genImageThumbs'
                options:
                    exchange:
                        name: 'genImageThumbs'
                retry_strategy:
                    max_retries: 1
                    multiplier: 2

            failed: 'doctrine://default?queue_name=failed'
            # sync: 'sync://'

        routing:
            SymfonyComponentMailerMessengerSendEmailMessage: async
            SymfonyComponentNotifierMessageChatMessage: async
            SymfonyComponentNotifierMessageSmsMessage: async

            # Route your messages to the transports
            AppMessageAsyncMessageInterface: async
            AppMessageSearchIndexMessageInterface: searchIndex
            AppMessageImageGenThumbsMessageInterface: genImageThumbs

Commands to start workers:

/usr/local/bin/php /var/www/html/app/bin/console messenger:consume genImageThumbs --limit=1500 --time-limit=86400
/usr/local/bin/php /var/www/html/app/bin/console messenger:consume searchIndex --limit=1500 --time-limit=86400
/usr/local/bin/php /var/www/html/app/bin/console messenger:consume async --limit=1500 --time-limit=86400

How do I pass form data to the next form page after sending to a php mailto page?

I have a few forms on my website which I need site visitors to submit in sequence.

‘form1’ sends the user data to the (php mailto) form mailer.

The header(location) of the form mailer then directs the site visitor to a page with ‘form2’.

I need a php solution to pre-populate form2 with the previously submitted data from form1.

I would like a slicker alternative to passing the data through the URL.

Form 1:

<form id="form1" action="formMailer.php" method="post">
   Name:&nbsp;<input type="text" id="userName" name="userName" value="">
   Email:&nbsp;<input type="email" id="userEmail" name="userEmail" value="">
<input type="submit" id="submitButton" name="submitButton" value="Submit">

PHP Form Mailer:

<?php 

    $name = $_POST['userName']; 
    $email = $_POST['userEmail']; 

    $message =

       "rnYour Name: "  .$name .
       "rnYour Email: "  .$email;

    $subject ="Subject of email";

    $mailto = "[email protected]";

    $separator = md5(uniqid(time()));

    $eol = "rn";

$headers = "From: ".$name." <".$email.">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed;". $eol. " boundary="" . $separator . """ .  $eol;
$headers .= "This is a MIME encoded message." . $eol . $eol;

$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset="iso-8859-1"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
$body .= $message . $eol;

   mail($mailto, $subject, $body, $headers);

   header('location: /formFolder/form2.php');

?>

Form 2:

<form id="form2" action="nextAction" method="post">
   Name:&nbsp;<input type="text" id="userName" name="userName" value="">
   Email:&nbsp;<input type="email" id="userEmail" name="userEmail" value="">
   Other Data:&nbsp;<input type="text" id="other_userData" name="other_userData" value="">
<input type="submit" id="submitButton" name="submitButton" value="Submit">

I tried some php ‘get’ and ‘echo’ script, but it seems the data gets lost somewhere between the mailto and the second form.

PHP error thrown when Registering/submitting the Form [duplicate]

PHP throws errors when submitting the form or registering the user. The array key is already set in the HTML form for gender and hobbies; then it also throws errors when submitting the form. Also, I don’t know how to solve the type error implode function is throwing. The following list of errors is coming.

  1. Warning: Undefined array key “gender” in C:xampphtdocsmainoldProjectsdemoTestinsertData.php on line 35

  2. Warning: Undefined array key “hobbies” in C:xampphtdocsmainoldProjectsdemoTestinsertData.php on line 36

  3. Fatal error: Uncaught TypeError: implode(): Argument #1 ($array) must be of type array, string given in C:xampphtdocsmainoldProjectsdemoTestinsertData.php:

index.php HTML code

<?php 'config.php'; ?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Demo Test</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
  <link rel="stylesheet" href="style.css">

</head>

<body>
  <section class="vh-100 gradient-custom">
    <div class="container py-3 h-100">
      <div class="row justify-content-center align-items-center h-100">
        <div class="col-12 col-lg-9 col-xl-7">
          <div class="card shadow-2-strong card-registration" style="border-radius: 15px;">
            <div class="card-body p-4 p-md-5">
              <h3 class="mb-2 pb-md-0 mb-md-5">Registration Form</h3>
              <form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">

                <div class="row">
                  <div class="col-md-6 mb-4">
                    <div class="form-outline">
                      <input type="file" name="userImage" class="form-control" />
                    </div>
                  </div>
                  <div class="col-md-6 mb-4">
                    <img src="" alt="" height="100px" width="100px" class="float-end" />
                  </div>
                </div>

                <div class="row">
                  <div class="col-md-6 mb-2">

                    <div class="form-outline">
                      <input type="text" name="userName" class="form-control form-control-lg" />
                      <label class="form-label">User Name</label>
                    </div>

                  </div>
                  <div class="col-md-6 mb-2">

                    <div class="form-outline">
                      <input type="email" name="email" class="form-control form-control-lg" />
                      <label class="form-label">Email</label>
                    </div>

                  </div>
                </div>

                <div class="row">
                  <div class="col-md-6 mb-2">

                    <div class="form-outline">
                      <input type="text" name="password" class="form-control form-control-lg" />
                      <label class="form-label">Password</label>
                    </div>

                  </div>
                  <div class="col-md-6 mb-2">

                    <div class="form-outline">
                      <input type="tel" name="phoneNumber" class="form-control form-control-lg" />
                      <label class="form-label">Phone Number</label>
                    </div>

                  </div>
                </div>

                <div class="row">
                  <div class="col-md-6 mb-2">
                    <h6 class="mb-2 pb-1">Gender: </h6>

                    <div class="form-check form-check-inline">
                      <input type="radio" name="gender" class="form-check-input" value="Male" />
                      <label class="form-check-label">Male</label>
                    </div>

                    <div class="form-check form-check-inline">
                      <input type="radio" name="gender" class="form-check-input" value="Female" />
                      <label class="form-check-label">Female</label>
                    </div>

                  </div>
                  <div class="col-md-6 mb-2">
                    <h6 class="mb-2 pb-1">Hobbies: </h6>

                    <div class="form-check form-check-inline ">
                      <input class="form-check-input" type="checkbox" name="hobbies[]" value="Reading" />
                      <label class="form-check-label">Reading</label>
                    </div>

                    <div class="form-check form-check-inline ">
                      <input class="form-check-input" type="checkbox" name="hobbies[]" value="Writing" />
                      <label class="form-check-label">Writing</label>
                    </div>

                    <div class="form-check form-check-inline ">
                      <input class="form-check-input" type="checkbox" name="hobbies[]" value="Traveling" />
                      <label class="form-check-label">Traveling</label>
                    </div>

                  </div>
                </div>

                <div class="mt-2 pt-2 d-grid gap-2 col-6 mx-auto">
                  <button type="submit" name="submit" class="btn btn-primary btn-lg">Register</button>
                </div>

                <?php include 'insertData.php'; ?>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
    crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
    integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
    crossorigin="anonymous"></script>
</body>

</html>

insert.php PHP code

<?php
include('config.php');

#file upload
if (isset($_FILES['userImage'])) {
    $errors = array();

    #set file attributes
    $fileName = $_FILES['userImage']['name'];
    $fileTmpName = $_FILES['userImage']['tmp_name'];
    $fileSize = $_FILES['userImage']['size'];
    $fileType = $_FILES['userImage']['type'];

    $tmpExt = explode('.', $fileName);
    $fileExt = strtolower(end($tmpExt));
    $extensions = array("jpg", "png", "jpeg");

    if (in_array($fileExt, $extensions) === FALSE) {
        $errors[] = "Only JPG, PNG files are allowed !";
    } elseif ($fileSize > 2097152) {
        $errors[] = "File size must be 2MB or lower !";
    } elseif (empty($errors) == TRUE) {
        move_uploaded_file($fileTmpName, "upload/" . $fileName);
    } else {
        print_r($errors);
        die();
    }
}

if (isset($_POST['submit'])) {
    $userName = $_POST['userName'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $phoneNumber = $_POST['phoneNumber'];
>     $gender = $_POST['gender'];
>     $tmpHobbies = $_POST['hobbies'];
>     $hobbies = implode(',', $tmpHobbies);

    if (empty($userName) || empty($email) || empty($password) || empty($phoneNumber) || empty($gender) || empty($hobbies)) {
        echo "<div class='col-sm-4 text-bg-danger p-2 mt-2'>All the fields are required !</div>";
    } else {
        $insertQuery = "INSERT INTO `users`(`username`, `email`, `password`, `gender`, `hobbies`, `phoneNumber`, `userPhoto`) VALUES ('$userName','$email','$password','$gender','$hobbies','$phoneNumber','$fileName')";

        if ($conn->query($insertQuery) === TRUE) {
            echo "<div class='col-sm-4 text-bg-success p-2 mt-2'>Registration Success.</div>";
        } else {
            echo "<div class='col-sm-4 text-bg-danger p-2 mt-2'>Registration failed.</div>";
        }
    }
}
?>

Registration Form