Re: Re[2]: [SMARTY] include_php file with paramters?
| From: | Andr� Rabold | Date: | Thu, 07 Nov 2002 07:17:38 +0000 |
| Subject: | Re: Re[2]: [SMARTY] include_php file with paramters? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6346@lists.php.net to get a copy of this message | ||
That's right. For this reason I have implemented a forward functions which
makes it possible
to include php scripts with additional parameters:
forward('http://www.example.com/mypage.php?myparam1=1&myparam2=2');
It includes the page "mypage.php" and then modifies the $_POST, $_GET and
$_REQUEST
variables so the script will recognize the parameters.
It works quite good for me. It should be easy to write your custom Smarty
resource which
uses this function. Then the following should be no longer a problem
{include
file="forward:http://www.example.com/mypage.php?myparam1=1&myparam2=2"}
Improvements are welcome ;-)
function forward( $url = NULL ) {
if (is_null($url))
die("ERROR: Cannot forward to empty url.");
if (strchr($url,"?")) { // it's a url with parameters, we need some
preprocessing
$url = explode("?", $url);
$getvars = Array();
$request = explode("&", $url[1]);
foreach ($request as $param) {
list($key, $value) = explode("=", $param);
$getvars[$key] = $value;
}
unset($_GET); // a little hack - who has a better solution?
$_GET = $getvars;
$_SERVER["QUERY_STRING"] = $url[1];
$_SERVER["REQUEST_URI"] = $url[0]."?".$url[1];
if (isset($GLOBAL["QUERY_STRING"])) $GLOBAL["QUERY_STRING"] =
$_SERVER["QUERY_STRING"];
if (isset($GLOBAL["REQUEST_URI"])) $GLOBAL["REQUEST_URI"] =
$_SERVER["REQUEST_URI"];
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
// now cleanup vars
unset($getvars);
unset($request);
unset($param);
unset($key);
unset($value);
// Now you could extract the $_GET vars to simulate a
"register_globals" functionality
// extract($_GET);
// remeber that the $_POST array is still available and does't need
a preprocessing!
$url = $url[0];
}
include ($url);
}
Have fun,
André
"Guido" <sguido@rogers.com> schrieb im Newsbeitrag
news:17823493952.20021106190639@rogers.com...
>
> the problem is that this doesn't work in php either.
>
> You can't use an include like:
>
>
> include('http://url.of.thepage&your=query&string');
>
> it has to be an actual page.
>
>
> Wednesday, November 6, 2002, 5:26:34 PM, you wrote:
>
> JJ> Then maybe you can just use: (untested!)
>
> JJ> {include_php
> JJ> file=http://url.of.thepage&your=query&string=}
>
> JJ> I'm pretty sure {include_php} is just a wrapper for the standard php
> JJ> function include(), and if your php environment allows it (it does by
> JJ> default), you should be able to grab a remote url in the same manner.
>
> JJ> Somebody correct me if I'm wrong, please! :)
>
> JJ> -- Josh
>
> JJ> -----Original Message-----
> JJ> From: news [mailto:news@main.gmane.org] On Behalf Of ksi
> JJ> Sent: Wednesday, November 06, 2002 5:20 PM
> JJ> To: smarty-general@lists.php.net
> JJ> Subject: Re: [SMARTY] include_php file with paramters?
>
> JJ> Josh Johnson wrote:
> >> So your not including a php file to execute, your trying to include a
> >> remote file that will return something?
> >>
>
> JJ> The include file show the output of a newsticker. This include file
> JJ> includes another .inc files etc.
> JJ> The Newsticker you can see under www.ksile.de (without smarty :) )
>
> JJ> cu ksi
>
>
>
>
> JJ> --
> JJ> Smarty General Mailing List (http://smarty.php.net/)
> JJ> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>
>
> --
> Best regards,
> guido mailto:sguido@rogers.com
>