Click to See Complete Forum and Search --> : How can I share the POST data with two php file
reinmontreal
11-11-2005, 10:44 AM
Hi,
I have three php files: A.php, B.php and C.php, A.php will post data to B.php. Now I want C.php also can get the _POST data in A.php. I have read the thread http://www.webdeveloper.com/forum/showthread.php?t=84206&highlight=post . But I am using php3 in my board, so I can't use session().
Does anyone know how to share the POST data within two php files?
Thanks in advance!
Reinmontreal
emin3m
11-11-2005, 12:13 PM
hmm
not tested but should work
here are three files
a.php
<form action="b.php" method="post" name="inputform" target="_blank">
<input type="text" name="anything" value="anythinganything">
<input type="submit" onclick="form_submit()">
</form>
<script language="javascript">
function form_submit(){
document.inputform.submit();
document.inputform.target="";
document.inputform.action="c.php";
document.inputform.submit();
}
</script>
b.php
<?php
echo @$_REQUEST['anything']." on page B";
?>
c.php
<?php
echo @$_REQUEST['anything']." on page C";
?>
emin3m
11-11-2005, 12:15 PM
oh yeah it works :D
check http://www.fkn1337.com/a.php
reinmontreal
11-11-2005, 12:33 PM
Thanks a lot, Emin3m! I am now trying your code in my file.
bokeh
11-11-2005, 12:51 PM
If you want to share data between PHP pages ($_POST data or any other data) you should be using sessions (http://es2.php.net/session) not javascript.
reinmontreal
11-11-2005, 12:57 PM
If you want to share data between PHP pages ($_POST data or any other data) you should be using sessions (http://es2.php.net/session) not javascript.
Yes, but the problem is I am using php3 and php3 doesn't support sessions. :(
bokeh
11-11-2005, 01:03 PM
Yes, but the problem is I am using php3 and php3 doesn't support sessions. :(Is there a good reason why?
reinmontreal
11-11-2005, 01:09 PM
Emin3m, I met another problem when I was trying the code since I didn't explain my situation very clearly before: I have a select box and a "Save" button in A.php, when I press the "Save" button, the post data can be gotton in B.php; when a certain item ("Add New") is selected in the selct box, the POST data should be sent to C.php ans also C.php will be load. In your code, when we press the "Submit Query" button, submit() will be called twice and then both B.php and C.php can get the data. But I don't know how to triger "submit" when I select the "Add New" item in the select box.
Thanks!
Reinmontreal
reinmontreal
11-11-2005, 01:12 PM
Is there a good reason why?
Hi Bokeh, my company's product currently is using php3. We have no time now to switch to php4 or php5 immediately.
mitcon
11-11-2005, 01:25 PM
Reinmontreal:
Just to play Devil's advocate...what are your thoughts for the people that have JavaScript disabled? There is are a fair amount of people out there that disable JS. In one of the major online Photography communities, I would say approaching 50%.
Why not send them on to the third page via Hidden form variables on a POST form (hides the variables from the would be miscreant).
Also...
I'm surprised that you have access to $_REQUEST in PHP v. 3.x. Everything that I've read indicates that these Super Globals weren't there until PHP 4.1.0.
When using the POST method ALWAYS use the $_POST['anything'] super global. If you use $_REQUEST['anything'] you don't know if you received $_GET['anything'], $_POST['anything'] or $_COOKIE['anything']. $_REQUEST is a conglomeration of all of those variables. In addition, there's a pecking order as to which value gets stored in the $_REQUEST['anything'] variable; ie. if you set $_COOKIE['anything']='foo' and $_GET['anything']='bar' one will take preference over the other in the $_REQUEST['anything'] array. Go here for a full discussion of the Super Globals:
http://us2.php.net/variables.predefined
By the way emin3m ... love the Avatar! Hilarious!
reinmontreal
11-11-2005, 02:45 PM
Problem solved!
When the "Add New" item is selected in the checkbox, the function new_submit() will be called:
function new_submit(){
document.my_form_name.target="";
document.my_form_name="C.php";
document.my_form_name.method="post";
document.my_form_name.submit();
}
Then I can use POST method to get data in C.php.
Thanks a lot, Emin3m, Bokeh and Mitcon!
emin3m
11-12-2005, 02:54 AM
By the way emin3m ... love the Avatar! Hilarious!
lol thanx
and nice for explaing him, i was using my $_REQUEST style :D
appriciated reinmontreal!