1

so if I have a file:

test1.php

which has a variable $var1 = $_POST['username'];

is there anyway I can access that variable in another file:

test2.php

echo $var1; 

without having to set a session? as currently It produces an undefined error

TessRay97
  • 121
  • 1
  • 8
  • I'm guessing the post goes to test1.php, which then redirects the user to test2.php ... ? – IncredibleHat Mar 02 '18 at 15:28
  • pass it via querystring, include test1 in test2 possibly – Professor Abronsius Mar 02 '18 at 15:28
  • yes... one way would be to pass `$var1` value as a `GET` param to `test2.php`, in the event that `test2.php` is a link etc. from within `test1.php`... if not, then the only other way I can think of is by using `$_SESSION`, as you alluded to, in your question. – Rushikumar Mar 02 '18 at 15:33

1 Answers1

0

You can use: include 'test1.php'; in test2.php. Then echo $var1; in test2.php.

  • that creates an error saying that $var1 is undefined – TessRay97 Mar 02 '18 at 15:31
  • I agree with @TessRay97 --- in order for `$var1` to **NOT** be *undefined* is to execute `test2.php` such that it has a `$_POST` param... then it should be okay... otherwise, not so! – Rushikumar Mar 02 '18 at 15:35