Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Passing variables from one page to another

I am trying to pass on the value of one variable from one PHP page to another PHP page, but for some reason, it's not working..

Here's my code for phpOne.php:

<?php
    $x = 100;
    $_SESSION['sessionVar'] = $x;
    echo "$x";
?>

And here's my code for phpTwo.php:

<?php
$x = $_SESSION['sessionVar'];
echo "$x";
?>

Thanks in-advance! Tom!

like image 894
Thomas Gouder Avatar asked Dec 07 '25 10:12

Thomas Gouder


1 Answers

You need to call session_start(); on both pages.

like image 194
Useless Intern Avatar answered Dec 10 '25 01:12

Useless Intern