0

I'm not even sure if 'variable scope' is the right term. I basically have a form submitted that sets variables. I then redirect conditionally based on some of them, then I need to retrieve some of them again. Currently, it works if I pass them as a Query String and receive via $_GET. I'd use $_POST but it's not the very next page.

I've got a Form page, the reloaded form page which forwards to a landing page. On the landing page, its www.domain.com/landingpage?foo=bar. I'd like a better method.

on the form, i've got

if(isset($_POST['foo'])){ $foo = $_POST['foo']; } else { $foo = ''; } 

because I need the variables set always, even if there's an error/blank field.

Then I redirect to

http://www.domain.com/landing?foo=bar 

and retrieve $_GET['foo'].

On the form page, how do I set the variable for use on the latter PHP pages?

4
  • Session Variables might do the trick? Commented Aug 22, 2012 at 19:08
  • you could try a session variable or a cookie. Commented Aug 22, 2012 at 19:08
  • Cookies would only work if the user agent allows them tho, correct? So would a Session Variable be a more 'reliable' way to go about it? Commented Aug 22, 2012 at 19:10
  • Session variables are dependent on cookies (to identify the correct session to use). Commented Aug 22, 2012 at 19:15

1 Answer 1

1

You probably want to utilize PHP sessions [by the way, variable scope isn't the right word]. Call session_start() at the top of each file, and then you can set variables in the $_SESSION superglobal which will persist across pages.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.