Google App Engine app.yaml PHP脚本参数 [英] Google App Engine app.yaml PHP scripting parameters
问题描述
应用程序:myapp
版本: 1
运行时:php
api_version:1
线程安全:是
处理程序:
- url:/sitemap.xml
static_files:sitemap.xml
上传:/sitemap\.xml
- url:/ MyOneLink
脚本:/myDynamicContent.php?myparam=hardcoded_value_1
- url:/ MySecondLink
script:/myDynamicContent.php?myparam=hardcoded_value_2
所以你可以浏览 http://example.com/MyOneLink 并获得动态php的结果(这取决于硬编码的myparam值)
问题在于浏览时没有显示任何内容。
的任何想法?
btw:你可以找出为什么我也发布一个sitemap.xml:它将用于公开所有myLinks p>
感谢
diego
其他答案都可以对于有限数量的硬编码值(如问题所示)。
但是,如果您想使用具有无限可能性值的真正动态版本,则可以(不起作用):
- url:/MyLinks/((* )/?
脚本:/myDynamicContent.php?myparam=\1
以上不起作用。您可以通过使用简单的PHP hack 解决该问题。
更新 app.yaml $ c $
- url:/MyLinks/.*
脚本:/myDynamicContent.php
在 myDynamicContent.php
中,获取 $ _ SERVER ['REQUEST_URI']
并解析此字符串以获取 myparam
的预期值。
更新!更优雅的方法:
<?php
$ requestURI = parse_url($ _ SERVER [REQUEST_URI ],PHP_URL_PATH);
$ requestURI = explode(/,$ requestURI);
$ myparam = $ requestURI [2];
echo $ myparam;
?>
自
parse_url
总是获取路径信息,我们可以安全地依靠硬编码索引。由explode
为字符串/ MyLinks / value_1
生成的数组将在索引 0处包含一个空字符串,MyLinks
位于 1 ,value_1
位于 2 ,等等。
原始庞克方法:
<?php
$ requestURI = explode(/,$ _SERVER [REQUEST_URI]); $ $ b $ for($ i = 0; $ i if(strcmp($ requestURI [$ i],MyLinks)== 0){
$ myparam = $ requestURI [$ i + 1];
休息;
}
}
echo $ myparam;
?>
提示:您可以使用单引号'
而不是双引号
In my GAE PHP app.yaml i am trying to do this:
application: myapp
version: 1
runtime: php
api_version: 1
threadsafe: yes
handlers:
- url: /sitemap.xml
static_files: sitemap.xml
upload: /sitemap\.xml
- url: /MyOneLink
script: /myDynamicContent.php?myparam=hardcoded_value_1
- url: /MySecondLink
script: /myDynamicContent.php?myparam=hardcoded_value_2
so one can browse http://example.com/MyOneLink and get the result of the dynamic php (which depends of the hardcoded myparam value)
the problem is that when browsing, nothing is shown. any idea ?
btw: you can figure out why i am also publishing a "sitemap.xml": it will be used to expose all myLinks
thanks diego
The other answers would be fine for a finite number of values that are hardcoded (as shown in question).
But if you want to work with a truly dynamic version with infinite possibilities of values, you may think of the following (does not work):
- url: /MyLinks/(.*)/?
script: /myDynamicContent.php?myparam=\1
The above does not work. You can workaround the problem by using a simple PHP hack.
Update the app.yaml
to:
- url: /MyLinks/.*
script: /myDynamicContent.php
In myDynamicContent.php
, get the value of $_SERVER['REQUEST_URI']
and parse this string to get the intended value for myparam
.
Update! More elegant method:
<?php
$requestURI = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
$requestURI = explode("/", $requestURI);
$myparam = $requestURI[2];
echo $myparam;
?>
Since
parse_url
always gets the path info, we can safely depend on hardcoded indices. The array produced byexplode
for string/MyLinks/value_1
will contain an empty string at index 0,MyLinks
at 1,value_1
at 2, and so on.
Original clunkier method:
<?php
$requestURI = explode("/", $_SERVER["REQUEST_URI"]);
for ($i = 0; $i < count($requestURI); $i++) {
if (strcmp($requestURI[$i], "MyLinks") == 0) {
$myparam = $requestURI[$i + 1];
break;
}
}
echo $myparam;
?>
Tip: You can use single quotes '
instead of double quotes "
这篇关于Google App Engine app.yaml PHP脚本参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!