Newbie PHP Question

TeamZero

Senior member
Apr 14, 2004
519
0
0
Is it possible to pass POST variables (declare a new one and pass it) to another page, without submitting a form?

The only way I know how to assign values to the $_POST array is by submitting a form with named inputs. Is there another way to do it?
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
So instead of a submit button, the user is just clicking a link? If so, you can use javascript to submit hidden form elements. Not exactly sure how to do it, but I know it's really easy.

Just reread your post. I'm not sure if you would consider this submitting a form.

This could possibly work:

$_POST['myvar'] = "astring";

Then on the next page:

$myvar = $_POST['myvar'];

That seems too simple though, so it doesn't seem like it would work.
 

TeamZero

Senior member
Apr 14, 2004
519
0
0
I know and understand sessions...but this function needs to happen right after my session is destroyed.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
Originally posted by: txrandom
Actually it would just be easier to use sessions:

sessions are great...until you have to scale your site into multiple servers :

TZ, do they have to be POST?
You can redirect to a url with the variables as url params (GET).

If they need to be POST, you can output the variables as hidden fields in a hidden form and autosubmit it with javascript (but its not the best practice)
 

TeamZero

Senior member
Apr 14, 2004
519
0
0
I understand GET varisbles as well.

It seems like it would be best to just use multiple sessions, since the only way to do it is submit hidden fields.

Thanks guys.

Edit: spelling
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
The very nature of the POST method requires a form POST. End of story.

If you want, you can use javascript to make a link submit a form, or use javascript to auto-submit a form when a page loads.