Passing values from one PHP script to another
I'm a beginner at PHP. I'm using Zend AMF which is used for RPCs. Once a particular function say Index.register()
has been cal开发者_开发技巧led by a client, I want it to invoke a script say Checker.php
in the same folder, by passing a 'name'
variable, which will constantly check the database for records associated with that 'name'
and perform operations on the DB. Will the Checker
script run independently of the Index
script? How shall the value be passed?
You may use session variables in PHP: the super globals array $_SESSION[] stores index/value pairs (variables, arrays and objects) across page requests. Practically:
$_SESSION['somevalue'] = $_GET['something'];
$_SESSION['myobject'] = new yourObject;
$_SESSION['loggedin'] = false;
So if - for example - a user succesfully logged in you may set $_SESSION['loggedin'] to true which can be accessed by all other scripts within the scope of the current PHP session. Also scripts may 'reuse' the same object if it is stored in the session (which may consume a lot of memory....).
If by invoking you mean include()
or require()
another script file it immediately becomes part of the same environment. So, in terms of including a script you don't have to do anything because you only extend the length of your script.
However, if you have a function or object in that file you have to deal with scope and pass the variables accordingly to the function or object.
精彩评论