我想要一些有PHP经验的人的建议.
我在php中建立一个网站,有4种用户:1.访客(未注册),2.注册,3.注册特殊权限,4.管理员
因此,对于所有这四个页面,同一页面将以不同方式显示.
现在我通过使用if条件来做到这一点.在每个页面中,我正在检查role用户,然后使用许多if语句来相应地显示页面.
它使代码非常大且不整洁,我必须在所有页面中反复检查条件.
有一个更好的方法吗?
这是如何在大型专业网站上完成的?
扩展问题:使用像kohana 3.1这样的MVC框架,最好的方法是什么?它有什么关系acl吗?
我试图在PHP中使用YQL,使用amazon.prodlist表和亚马逊产品广告API 从亚马逊获取产品信息.
我使用的查询:
select * from amazon.prodlist where Title='harry potter' and SearchIndex='Books' and ResponseGroup='Images,ItemAttributes'
Run Code Online (Sandbox Code Playgroud)
它只返回10个结果.如何让它在同一页面上显示更多10个结果?而且,没有分页.
完整的PHP代码:
<?php
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
$key="my_key";
$secret="my_secret";
$title="harry potter";
$sindex="Books";
$rgroup="Images,ItemAttributes";
$events="";
// Form YQL query and build URI to YQL Web service
$yql_query = "use 'http://www.datatables.org/amazon/amazon.ecs.xml' as amazon.prodlist;
set AWSAccessKeyId='$key' on amazon.prodlist;
set secret='$secret' on amazon.prodlist;
select * from amazon.prodlist where Title='$title' and SearchIndex='$sindex' and ResponseGroup='$rgroup' ";
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
// Make call with …Run Code Online (Sandbox Code Playgroud) 我有两个 Amazon EC2 实例。让我称它们为 X 和 Y。我在它们上都安装了 nginx。Y 已在端口 上运行resque3000。只有 X 具有公共 IP 和域 example.com。假设Y的私有IP是15.0.0.10
我想要的是所有请求都到达 X。并且只有当请求 url 与模式匹配时/resque,它才应该由 Y at 处理localhost:3000/overview,这是 resque Web 界面。看来这可以使用 nginx 配置中的 proxy_pass 来完成。
因此,在 nginx.conf 中,我添加了以下内容:
location /resque {
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
allow all;
proxy_pass http://15.0.0.10:3000/overview;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Run Code Online (Sandbox Code Playgroud)
但现在,当我http://example.com/resque从网络浏览器访问时,它显示502 Bad Gateway.
在/var/log/nginx/error.logX 上,
2014/02/27 10:27:16 [error] 12559#0: *2588 connect() failed (111: …Run Code Online (Sandbox Code Playgroud) 我在端口 3000 的 Ubuntu Amazon EC2 实例上运行了一个 Web 服务器15.0.0.10。是这个 EC2 实例的私有 ip。
在我通过 ssh 进入这个实例并运行以下命令后curl localhost:3000/index.html,它会返回我的 index.html 页面的 html 源代码。
但是当我运行时curl 15.0.0.10:3000/index.html,它说:
curl: (7) couldn't connect to host
Run Code Online (Sandbox Code Playgroud)