samantha_chan1 Posted April 10, 2006 Share Posted April 10, 2006 how can i post a variable let's say $total from 1st page to xx.php while i am using a header("locaiton : xx.php") in 1st page? Quote Link to comment https://forums.phpfreaks.com/topic/7004-solved-post-varible-in-header-locationxxphp/ Share on other sites More sharing options...
Yesideez Posted April 10, 2006 Share Posted April 10, 2006 Set up a form in the firest page and make a hidden input:[code]<input type="hidden" name="cheeseopt" value="notliked">[/code]Then on the second script use something like this:[code]$cheese=$_POST['cheeseopt'];[/code]Use $_POST if in your form you use method="post" and $_GET if you use method="get"The difference is POST sends the form data in a packet whereas GET adds the form data onto the end of the URL and sends it that way - POST is more secure. Quote Link to comment https://forums.phpfreaks.com/topic/7004-solved-post-varible-in-header-locationxxphp/#findComment-25426 Share on other sites More sharing options...
samantha_chan1 Posted April 10, 2006 Author Share Posted April 10, 2006 [!--quoteo(post=363221:date=Apr 10 2006, 04:44 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 10 2006, 04:44 PM) [snapback]363221[/snapback][/div][div class=\'quotemain\'][!--quotec--]Set up a form in the firest page and make a hidden input:[code]<input type="hidden" name="cheeseopt" value="notliked">[/code]Then on the second script use something like this:[code]$cheese=$_POST['cheeseopt'];[/code]Use $_POST if in your form you use method="post" and $_GET if you use method="get"The difference is POST sends the form data in a packet whereas GET adds the form data onto the end of the URL and sends it that way - POST is more secure.[/quote]But i am posting the variable in a script to another page. the script is not in the html. so i can't but a hidden field in it. does there have any other solution? Quote Link to comment https://forums.phpfreaks.com/topic/7004-solved-post-varible-in-header-locationxxphp/#findComment-25430 Share on other sites More sharing options...
Yesideez Posted April 10, 2006 Share Posted April 10, 2006 Sure is, try this:[code]header("Location: newscript.php?param=value¶m2=value2");[/code]Then in the second script use $_REQUEST to get the contents of param and param 2 and so on.If you need help building the URL for the header() function something like this would work:[code]$var1=12;$var2="text";header("Location: scripttwo.php?param1=$var1¶m2=$var2");[/code]I have to go and do some work now :(Just for information, here is how you would read the vars in the second script:[code]$var1=$_REQUEST['param1'];$var2=$_REQUEST['param2'];[/code]Hope you get it sorted ;) Quote Link to comment https://forums.phpfreaks.com/topic/7004-solved-post-varible-in-header-locationxxphp/#findComment-25432 Share on other sites More sharing options...
samantha_chan1 Posted April 10, 2006 Author Share Posted April 10, 2006 [!--coloro:#CC66CC--][span style=\"color:#CC66CC\"][!--/coloro--][b]thanks a lot Yesideez.... you helped me a lot.[!--colorc--][/span][!--/colorc--][/b] Quote Link to comment https://forums.phpfreaks.com/topic/7004-solved-post-varible-in-header-locationxxphp/#findComment-25437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.