I want to know how to pass a variable from one page to another in PHP without any form.
What I want to achieve is this:
$myVariable = "Some text"; And the form's action for that page is "Page2. php".
There are two ways to pass variables between web pages. The first method is to use sessionStorage, or localStorage. The second method is to use a query string with the URL.
Three ways can pass the variable through the navigation between the pages: Put the variable into session in the first page, and get it back from session in the next page.
use the get method in the url. If you want to pass over a variable called 'phone' as 0001112222:
<a href='whatever.php?phone=0001112222'>click</a>
then on the next page (whatever.php) you can access this var via:
$_GET['phone']
You want sessions if you have data you want to have the data held for longer than one page.
$_GET
for just one page.
<a href='page.php?var=data'>Data link</a>
on page.php
<?php
echo $_GET['var'];
?>
will output: data
You can pass via GET. So if you want to pass the value foobar
from PageA.php
to PageB.php
, call it as PageB.php?value=foobar
.
In PageB.php, you can access it this way:
$value = $_GET['value'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With