How to Pass Variables Between HTML Pages

General | Updated March 2026

Plain HTML files cannot pass variables between pages on their own because HTML is a static markup language with no server-side processing. However, there are several approaches you can use, ranging from simple URL parameters to PHP sessions.

01. URL Query Strings (Simplest)

Append data to the URL as query parameters. This is the simplest method and works with plain HTML files.

Create the Link

<a href="page2.html?name=John&color=blue">Next Page</a>

Read the Parameters on page2.html

<script>
const params = new URLSearchParams(window.location.search);
const name = params.get('name');   // "John"
const color = params.get('color'); // "blue"
document.getElementById('greeting').textContent = 'Hello, ' + name;
</script>
Note

Query string data is visible in the URL and in browser history. Don't use this method for sensitive information like passwords or personal data.

02. Use PHP for Server-Side Variables

For more robust variable passing, rename your files from .html to .php and use PHP. This is the recommended approach for anything beyond simple values. PHP is fully supported on all Ultra hosting accounts.

$_GET - URL Parameters

Works like query strings but PHP reads them server-side:

// Link: page2.php?name=John
// On page2.php:
$name = $_GET['name']; // "John"
echo "Hello, " . htmlspecialchars($name);

$_POST - Form Submissions

For form data (not visible in the URL):

// form on page1.php:
<form method="post" action="page2.php">
  <input type="text" name="email">
  <button type="submit">Submit</button>
</form>

// On page2.php:
$email = $_POST['email'];

$_SESSION - Persist Across Multiple Pages

For data that needs to follow the user across many pages (shopping carts, login state):

// On any page - start session and store data:
session_start();
$_SESSION['username'] = 'John';

// On any other page - read it:
session_start();
echo $_SESSION['username']; // "John"
Tip

If you want to keep your .html file extensions but use PHP, you can add a handler to your .htaccess file. See our Parse HTML as PHP guide.

03. JavaScript localStorage

For client-side persistence across pages without any server processing. Data is stored in the visitor's browser and persists even after closing the tab.

// On page1.html - store data:
localStorage.setItem('name', 'John');
localStorage.setItem('color', 'blue');

// On page2.html - read data:
const name = localStorage.getItem('name');   // "John"
const color = localStorage.getItem('color'); // "blue"

// When done - clean up:
localStorage.removeItem('name');
Warning

localStorage is stored in the visitor's browser, not on the server. It can be viewed and modified by the user. Never use it for security-sensitive data. Also note that localStorage is per-domain and per-browser - data stored in Chrome won't be available in Firefox.

04. Which Method to Use

  • Simple values, no security concern - URL query strings. Quick, no server-side code needed
  • Form data, user input - PHP $_POST. Data isn't in the URL, can be validated server-side
  • Data across many pages (login, cart) - PHP $_SESSION. Server-side, secure, persists until session ends
  • Client-side only, no PHP - JavaScript localStorage. Works with plain HTML but less secure

For most websites on Ultra Web Hosting, PHP is the best choice since it's pre-installed, secure, and handles all these use cases. See our Server Paths guide for PHP binary locations.

Need Help With Your Code?

We can help with server configuration but not custom coding. For development help, consider a freelance developer or check our developer resources.

Open a Support Ticket

Last updated March 2026 · Browse all General articles · See also: Parse HTML as PHP

  • 151 Users Found This Useful

Was this answer helpful?

Related Articles

SSL - Creating a CSR in Windows 2003

Creating the CSR IIS Windows 2003 or 2000 Server: From Administrative Tools, run the Internet...

Point Multiple Domains to the Same Website

Pointing Multiple Domains to One Website   To have several domain names all display the same...

How do I cancel my account?

We are sorry to hear you would like to cancel your account! If there is anything we can do,...

osCommerce password reset

How to reset your osCommerce admin login... You can reset your osCommerce administrative login...

Enable AllowOverride

AllowOverride and .htaccess Support   AllowOverride is already enabled on all of our hosting...



Save 30% on web hosting - Use coupon code Hosting30