tommytx Posted February 11, 2015 Share Posted February 11, 2015 when I send a <form "get"> to another page i know to capture it with $dog = $_GET['dat'] but i need to know the variables..no problem I can see them in the URL.. But the question is what do I use to caputre the entire incoming post so i ca separated the variable from the data.. I also know that I can get one of the incoming variable with $cat = $_POST ['dat'] but I need the entire unknown huge post string to come in and get broken out as follows. $dog = "pet" $horse = "four legs" can someone help me... grab the entire post when it comes and break it down to varialbes and data even when I have no idea what the variables or data will look like.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/294529-how-to-capture-incoming-post-data-from-html-page/ Share on other sites More sharing options...
Psycho Posted February 11, 2015 Share Posted February 11, 2015 That can be done very easily, but it is a bad idea. If you just automatically create variables based on what is sent via POST/GET you are opening your application up to huge vulnerabilities. If you don't know what data is being sent and you create variables for it, how do you know how to use those variables? Perhaps you can give an explanation of what the situation is and what you are trying to accomplish. Because, what you are asking, doesn't seem realistic. 1 Quote Link to comment https://forums.phpfreaks.com/topic/294529-how-to-capture-incoming-post-data-from-html-page/#findComment-1505445 Share on other sites More sharing options...
Solution Ch0cu3r Posted February 11, 2015 Solution Share Posted February 11, 2015 grab the entire post when it comes and break it down to varialbes and data It already is. All data from the POST request is stored in the $_POST superglobal variable. To see the contents of $_POST use print_r (or var_dump) printf('<pre>Contents of $_POST %s</pre>', print_r($_POST, true)); 1 Quote Link to comment https://forums.phpfreaks.com/topic/294529-how-to-capture-incoming-post-data-from-html-page/#findComment-1505446 Share on other sites More sharing options...
QuickOldCar Posted February 11, 2015 Share Posted February 11, 2015 I agree, use the data already in the array and do checks on them. Usually when you write a script you want to know the parameters and data type to expect and should be checking for that. You want to do a check something like this. if(isset($_GET['dog']) && trim($_GET['dog']) != '') { $dog = trim($_GET['dog']); } else { $dog = ''; } If you loop through the array and make them variables.....is a bad idea because anyone can write a new GET parameter in the url and compromise your code, can overwrite a variable already had. terrible idea, don't do this whatever the key is would become a variable foreach($_GET as $key => $value){ $$key = $value; } if($dog){ echo $dog; } 1 Quote Link to comment https://forums.phpfreaks.com/topic/294529-how-to-capture-incoming-post-data-from-html-page/#findComment-1505451 Share on other sites More sharing options...
tommytx Posted February 11, 2015 Author Share Posted February 11, 2015 Thanks Ch0cu3r that was perfect.. exactly what I wanted.. you saved me several hours as I had already begun to go to each <input box and grab the name so that I could set up a post to receive that name.. wow .. that was a mistake there were over 500 variables.. wow.. so that printed the variable name and the value perfectly.... thanksagain.. Thanks Psycho for the warning.. would have been valuable to a beginner who did not know that.. but what I am doing is a one time closed capture of the "names" and initial data... before setting up to recevive the name and data in a normal post... so thanks for your input...I am sure you would have been able to answer had I been a little more clear... all you guy have been great... Quote Link to comment https://forums.phpfreaks.com/topic/294529-how-to-capture-incoming-post-data-from-html-page/#findComment-1505452 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.