0

I'm very new at PHP and have only written smaller easier scripts. I have a script on my server that does what I want it to do, however, at the end of the script I want to run another script on my server.

This other script takes $_POST like this:

$decoded = json_decode($_POST['arrayWithUserAndAvailable'], true); //does it's thing.. 

How do I call this script from within my other script?

Do I need to create an object out of it/class. Don't know how object oriented programming works in PHP.

If anyone can give me some guidance I would be grateful!

1
  • 1
    all you need is php.net/manual/en/function.include.php. However, when there wasnt any data posted to your including script, $_POST wont have the data you are trying to process. Commented Sep 17, 2011 at 15:45

2 Answers 2

1

Use include to add and parse another PHP file from within your script.

You can prevent your "other file" (the included file) from printing data using this method:

//PHP code ob_start(); //Start buggering the output include "otherfile.php"; ob_end_clean(); //Throw away the caught output // Anything defined in otherfile.php are also defined now. 

If $_POST['arrayWithUserAndAvailable'] does not exist in your caller, you might consider editing otherfile.php such that it can take arguments in an alternative way:

//otherfile.php $decoded = isset($decode) ? $decoded :$_POST['arrayWithUserAndAvailable']; //additional tests to ensure that $_POST["..."] is sane. $decoded = json_decode($decoded, true); //mainfile.php $decoded = "foo"; include "otherfile.php"; 
Sign up to request clarification or add additional context in comments.

Comments

0

It really depends on the way your code is laid out, and you haven't shown enough of it to be able to tell. "Calling the other script" may be as simple as using an include if it is not already in a class. Otherwise, you may wrap it in a class, put the logic inside of the constructor or some other method, and call as seen in the manual in the index or the basics. If you have a more specific question, elaborating may help.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.