Portal Home > Knowledgebase > Articles Database > Sending Post Info Without Involving Originating Script


Sending Post Info Without Involving Originating Script




Posted by gamemaster, 06-13-2010, 12:02 AM
The title may be confusing so let me explain. Script A collects info from a form and checks it for errors. When everything is Ok it seeks to insert it into a DB. Script B has the function to take some info from the same form and insert it into another DB. Script B does this by me using "include ('file')" however in doing so there are conflicts between the two files which cannot be adjusted because of the way they are coded. My problem is how do I pass on info from script A to script B using PHP only without A or B interacting with each other in any way. In other words just as script A is about to insert info in to its DB it also sends the info to script B silently. Script B should receive the data without trying to read script A or complications start hence why I cannot use Require or Include. Thanks for your help.

Posted by Mike Johnson, 06-14-2010, 11:31 AM
Have script A send a 303 redirect to script B and include the form information in the query string.

Posted by gamemaster, 06-14-2010, 11:33 AM
That's a good idea. I will do it through header redirection. Thanks.

Posted by sramadan, 06-14-2010, 01:41 PM
gamemaster, It seems to me like all you really want to do is pass form variables to Script B. For this I see to viable options. Of course MikeJohnson's idea of redirecting would work, but I personally hate redirecting scripts. I prefer sparing Apache the overhead (again no harm in redirecting though). One, you could always create a session and pass the form variables to the global scope (i.e. $_SESSION variables). Whenever the script is loaded it can retrieve the data from $_SESSION['whatever'] and you won't need to include the script. Instead use session_start() to load the session whenever the new script is called (this could also work with a redirect as opposed to passing the data to $_GET). Two, you can use an AJAX-type call to initialize the script asynchronously without creating an include instance. This may also require a session depending on what methods you're using to verify where the data is coming from. Let me know if you have any questions, or need any further clarifications / examples...

Posted by gamemaster, 06-14-2010, 01:45 PM
Thanks. Those are good ideas that I considered before but the problem is I really cannot modify script A the most I could do is have an include. In the end I included a third script C that collects info and then forwards it to B under a different URL so that script A is not known. May be it is dirty coding but it got the job done.

Posted by sramadan, 06-14-2010, 01:55 PM
Seems like a loop-d-loop to me. No idea why would want to do that when one line of code in script A and one line of code in script B could get the job done. All you really need to add to script A is something like... Then you can retrieve all session variables from script B the same way...but glad it worked for you

Posted by KMyers, 06-14-2010, 02:43 PM
Greetings,



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
ssh command to do this (Views: 495)
Dedicated MySQL Server (Views: 479)