Calling PHP-Script from a PHP-Script??
Moderator: General Moderators
- derschamane
- Forum Newbie
- Posts: 6
- Joined: Fri Dec 27, 2002 1:44 pm
- Location: Austria
- Contact:
Calling PHP-Script from a PHP-Script??
Seems to be a simple problem, but I was not able to found any hints:
I would like to call a PHP-Script from a PHP-Script
Example:
phpscript1.php
If ($check1 > 0)
{
phpscript2.php?ErrorNr=$check1
}
If $check1 is greater than 0, the Second Script should be called with the parameter as shown above.
Has anybody of you an idea, how to program this?
Any suggestions and hints are very welcome
Regards from Austria
Ewald, the modern shaman
I would like to call a PHP-Script from a PHP-Script
Example:
phpscript1.php
If ($check1 > 0)
{
phpscript2.php?ErrorNr=$check1
}
If $check1 is greater than 0, the Second Script should be called with the parameter as shown above.
Has anybody of you an idea, how to program this?
Any suggestions and hints are very welcome
Regards from Austria
Ewald, the modern shaman
Probably the best (and only?) way to do this, is executing it via command. I'm not %100 sure though if you can pass variables via query string. Might want to Google that if it doesn't work.
If you want the output of phpscript2.php returned, look into using system() instead.
Code: Select all
if ($check1 > 0)
{
$command = '/path/to/php -f /path/to/phpscript2.php?ErrorNr='.$check1;
exec($command);
}Well, yes its a different page, but from the details given that might be enough. You can't tell if we need to spawn a new process, if we need the results from the new process, etc. While I use PHP for shell scripts sometimes, most people don't. Many people don't even have a cli-php compiled/availible.
Header is also safer as you don't need to cleanse all the dangerous shell arguments, etc. But this is only an option if the user wants to pass full control to the new page.
Header is also safer as you don't need to cleanse all the dangerous shell arguments, etc. But this is only an option if the user wants to pass full control to the new page.
- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
You could also...
You could try the following, but it would probably only work for the web.
If you set up phpscript2.php to just write the output out without formatting (or in XML or something else useful) you could use the result in phpscript1.php.
Code: Select all
$fp = fsockopen("127.0.0.1", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, "GET phpscript2.php?ErrorNr=$check1 HTTP/1.0\r\n");
fwrite($fp, "Host: 127.0.0.1\r\n\r\n");
while(!feof($fp)) {
$result .= fread($fp, 512);
}
fclose($fp);
}- derschamane
- Forum Newbie
- Posts: 6
- Joined: Fri Dec 27, 2002 1:44 pm
- Location: Austria
- Contact:
Finally a real nice solution...
Finally I found a real nice and simple solution - thanx for every answer, I appreciate your help and at least your ideas gave me the final hint.
if ($check1)
{
echo "<script type=\"text/javascript\">";
echo "document.location.href = \"news_fehlerausgeben.php?ErrorNr=" . $check1 . "\"";
echo "</script>";
}
Conclusion: Sometimes, I've to look over the fence -> JavaScript instead of PHP
Ewald, the modern Shaman
http://www.schamane.cc[syntax=php]<?php
?>[/syntax]
if ($check1)
{
echo "<script type=\"text/javascript\">";
echo "document.location.href = \"news_fehlerausgeben.php?ErrorNr=" . $check1 . "\"";
echo "</script>";
}
Conclusion: Sometimes, I've to look over the fence -> JavaScript instead of PHP
Ewald, the modern Shaman
http://www.schamane.cc[syntax=php]<?php
?>[/syntax]