Skip to content

Pass data from PHP to HTML

Edit: Thank you for your help and time. I will change all my extension to .php as recommended and check the link that was shared :)!

I’m a beginner at coding and I have been stuck for a few days on a problem. So, I have coded a html page with a login form. Once the user click the button login, the username and password will be checked in a php file and then if it’s correct, the user will be redirected to the successfully login html page. I get redirected to the success login html page but I just can’t pass the user data, I have tried to add a .htaccess so I can try to echo the session username but it doesn’t display the username.

How do I pass the data of the user session to the new html page? I have been looking on forum and online but didn’t really find an answer. If you guys have advices or suggestions, it would be helpful as I’m a beginner. Thanks for your answers and help!

Here is the php part of what should happen if the user successfully login:


if(password_verify($password, $row["password"]) {  
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $username;
    header( 'Location: http://successfullogin.html' );

The successfullogin.html code:

<!doctype html>
<meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1, 
<link rel="stylesheet" href="/css/style.css">
<script src="/js/script.js"></script>


<h1>Sucess login </h1>
echo $_SESSION[‘username’];







You can’t run PHP in .html files cause the server don’t recognize that extension as a valid one. To tell your server to understand html files as valid check this topic below

How do I add PHP code/file to HTML(.html) files?

Or change your successfullogin.html to successfullogin.php

2 People found this is helpful