View Full Version : POST data
anurag.sharma
Jun 26th 2008, 10:04 am
I have an html form(say data.html) that will POST data to a php file(say, a.php). I wish to have that php page (a.php) to submit the same data to another php (say, b.php) file (using POST function) with out any input from the user.
Please suggest some way.
Weirfire
Jun 26th 2008, 10:20 am
You could try using some javascript;
<body onload='document.myform.submit();'>
<form name='myform' action='mypage.php' method='POST'>
<input type='hidden' name='field1' value='<?=$_POST['field1']?>' />
</form>
Alternatively you could use sessions and store your posted variables in the session and just redirect the user to the 2nd page;
<?php
session_start();
foreach($_POST as $field => $value){
$_SESSION[$field] = $value;
}
header('Location: mypage.php');
?>
Danltn
Jun 26th 2008, 11:05 am
Couldn't you just do $_SESSION = $_POST instead of that loop?
Dan
anurag.sharma
Jun 26th 2008, 11:56 am
thanks for the help.
but have some problem in implement ion
Here is the code I used
<?php
preg_match('/I am from ([a-z]+)/i',$_POST['search_var'],$match);
#print_r($_POST);
#print_r($match);
session_start();
if(isset($_POST['search_var'])) {
$_SESSION = $_POST
header('Location: '.$match[1].'.php');
exit;
?>
I want the user to be redirected to the next page and prints the data he entered.
If he had entered the data as
"I am from usa. How are you?" He should be redirected to usa.php and that page should display
"I am from usa. How are you?"
projectWORD
Jun 26th 2008, 5:17 pm
So you want to have a data form, a user enters data, the data submits and shows the user what data he has entered, then finally he confirms??
If this is the case then you can just pass the variables to the a.php script which will do the relevant database work or woteva. This script can then build then html placing the appropriate variable values in the appropriate places on the page. The user can then click confirm to complete which will run b.php to do final database work and finally display success page.
Im not too sure on what you are asking but that is how I would do what I think your asking :)
Weirfire
Jun 27th 2008, 2:31 am
Couldn't you just do $_SESSION = $_POST instead of that loop?
Dan
lol yeah that works for me too. I'd like to hire you to reduce my code. :D
anurag.sharma
Jun 27th 2008, 2:41 am
yes. that is what i need. could you please reedit the code for me?
anurag.sharma
Jun 27th 2008, 5:19 am
I am having some problem while using
header('Location: '.$match[1].'.php');
in session
Please help
anurag.sharma
Jun 27th 2008, 6:17 am
Danltn, could you help?
Danltn
Jun 27th 2008, 6:48 am
lol yeah that works for me too. I'd like to hire you to reduce my code. :D
Then please do. :D
___________________________________
Your first HTML file I assume you already have... This goes to the first PHP, I'm not going to include any decent validation here as I assume you can do it yourself...
<?php
/**
* Danltn | http://danltn.com/
* MSN: msn@danltn.com
* Email: daniel@neville.tk
* Started: 27/6/2008 15:02 (UK)
* Tested: No
* PHP 4/5: Both
* No warranty is given to code used
*/
$buffer = ''; // Initialize the variables.
$hidden = '';
$_POST = array_map('htmlentities', $_POST); // Very basic validation, stops XSS
foreach($_POST as $key => $value) :
$hidden .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />' . "\n";
$buffer .= ucwords(strtolower($key)) . ': ' . $value . '<br />' . "\n";
endforeach;
unset($key, $value); // Remove what we've used, get some more memory
?>
<form method="post" action="b.php">
Your input:<br />
<?php echo $buffer , $hidden; ?>
Submit: <input type="submit" name="submit" value="It's all correct!" />
</form>
anurag.sharma
Jun 28th 2008, 2:01 am
But the automatic redirection will not work in this case.
If the user enters the data as
"I am from usa. How are you?" He should be redirected to usa.php and that page should display
"I am from usa. How are you?"
And if he enters
"I am from uk. How are you?" He should be redirected to uk.php and that page should simply display
"I am from uk. How are you?"
A simple redirection the respective page (say usa.php or uk.php) is what I require (along with the POST data).
I require your help in this aspect
itnashvilleCOM
Jun 28th 2008, 2:09 am
Can also use curl to send to a second script.
Weirfire
Jun 28th 2008, 2:22 am
Can also use curl to send to a second script.
I think he needs a little more guidance than that. Would you care to expand upon your post?
anurag.sharma
Jun 28th 2008, 3:27 am
Could you please explain with some code?
anurag.sharma
Jun 28th 2008, 5:49 am
i found some info in'
http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html
can any one help me in applying that to my scripts and retain the "header('Location: '.$match[1].'.php');" in the script
anurag.sharma
Jun 30th 2008, 1:51 am
can any one help?
enchance
Jun 30th 2008, 3:23 am
Why not just use a hidden form? Once "a.php" passes data to "b.php" through a form using POST, simply receive the value in "b.php" through $_POST['val'] and place them in a hidden form for sending to "c.php" also through POST. This allows you to pass information to an infinite number of pages using POST.
Alternatively, instead of having to list down every variable you receive form POST, you can use this instead which mimics the config "register_globals=on" when in reality it's really off:
//makes variables of the "name" attribute of your forms and
//assigns the "value" attribute to it automatically. Cool yah?
foreach ($_POST as $key => $val){
$$key = $val;
}
If you have a form with name="address", you can simply access its value as $address without having to go through
$address = $_POST['address'];
Danltn
Jul 6th 2008, 1:48 pm
enchance:
Well if you want vulnerabilities, just use:
extract($_POST);
(It's the same as that loop, but with more options ;) )
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.