Skip to content
Advertisement

Can i carry PHP variables over into an HTML or Javascript file

I’m new to PHP and am trying to create an Age Validation form that will limit access to specific content on a site if a user is under a certain age.

This is the HTML form (index.html):

JavaScript

and this is the PHP script(data.php):

JavaScript

I would like to be able and carry the resulting $limited variable from the PHP file into this HTML file:

JavaScript

This is currently just for testing to make sure it can carry over. I have tried the $_SESSION method but i can’t seem to figure it out.

Any and all possible solutions welcomed.

Thank you

Advertisement

Answer

First, your HTML file must be parsed by the PHP interpreter so it must have the .php extension in order to access any session variable.

Here’s an example with 3 files in the same directory based on your question:

index.html

JavaScript

data.php:

JavaScript

new.php(the new page, where you access your session variable)

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement