我想知道创建不可登录帐户的最佳做法是什么.在StackOverflow上,有一个社区Wiki帐户,我假设无法登录.
我应该如何为不可登录的帐户编写脚本?如果有一个我不想访问的帐户,我应该设置参数,就像你不能登录ID小于0的帐户一样吗?或者我应该只是手动定义配置ID中无法登录的ID?或者,还有更好的方法?
原始问题:
我读了RESTful网站.使用$ _SESSION是不好的.为什么不好?那么如何在不查找数据库的情况下对用户进行适当的身份验证以检查用户的角色?
我读到使用$ _SESSION是不好的.
http://www.recessframework.org/page/towards-restful-php-5-basic-tips
我正在创建一个网站,而不是PHP中的Web服务.而我正在努力使它更加RESTful.至少在精神上.
现在我正在重写使用Form标签POST的所有操作,并添加一个名为_method的隐藏值,删除操作将为"delete",更新操作将为"put".
但是,我不确定为什么建议不要使用$ _SESSION.我想知道为什么以及我该怎么做才能改进.
为了便于授权检查,我做的是登录用户后,用户名存储在$ _SESSION中.
每当用户导航到页面时,页面将检查用户名是否存储在$ _SESSION中,然后基于$ _SESSION检索包括数据库特权在内的所有信息,然后根据检索到的信息评估访问页面的授权.
我实施的方式是不是很糟糕?不RESTful?我如何提高性能和安全性?
谢谢.
有没有办法将无限量的参数传递给函数,并访问所有这些参数,而无需在标题中定义每个参数.这是一个让它更清晰的例子:
function doSomething($var1="", $var2="".........)
{
// Do something with the arguments
}
Run Code Online (Sandbox Code Playgroud)
我不想要定义一堆参数.有没有办法只获取数组中的所有参数?即使他们没有被定义?(PHP BTW)
最终结果应如下所示:
func("hello", "ya", "hi", "blah", "test", "go");
function func()
{
//Loop Over Arguments
}
Run Code Online (Sandbox Code Playgroud)
我已经看到一些本机PHP函数能够接受看似无限数量的参数,但用户定义的函数可以做同样的事情吗?
当我使用C++和winsock库访问" http://www.whatsmyip.org/ " 时,如何获得相同的IP地址?
我知道如何获得"127.0.0.1"和路由器IP"192.168.1.103"...但是当我到" http://www.whatsmyip.org/ "时,我得到"65.55.105.132"......
我怎么能做到这一点?
我有一个ruby应用程序从字符串解析一堆URL:
@text = "a string with a url http://example.com"
@text.split.grep(/http[s]?:\/\/\w/)
@text[0] = "http://example.com"
Run Code Online (Sandbox Code Playgroud)
这很好用^^
但有时URL在HTTP://之前有文本
@text = "What's a spacebar? ...http://example.com"
@text[0] = "...http://example.com"
Run Code Online (Sandbox Code Playgroud)
是否有正则表达式可以在字符串中选择"http://"之前的文本,以便我可以将其删除?
有10个表,我就没有联接.有了100个表,每个查询我会有一个连接.哪个会表现出更好的表现?
在PHP中,如何在类中的函数中使用外部$ var?例如,假设$ some_external_var设置为true,你有类似的东西
class myclass {
bla ....
bla ....
function myfunction() {
if (isset($some_external_var)) do something ...
}
}
$some_external_var =true;
$obj = new myclass();
$obj->myfunction();
谢谢
阅读代码中的注释以获取描述:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function __construct($configSection){
$rootDir = dirname(dirname(__FILE__));
define('ROOT_DIR',$rootDir);
set_include_path(get_include_path()
. PATH_SEPARATOR . ROOT_DIR . '/library/'
. PATH_SEPARATOR . ROOT_DIR .
'application/models'
);
//PROBLEM LIES HERE, BEWARE OF DRAGONS.
//Using this, I receive a deprecated warning.
include 'Zend/Loader.php';
Zend_Loader::registerAutoload();
//Using this, I recieve an error that autoload() has missing arguments.
//Zend_Loader_Autoloader::autoload();
//Load the configuration file.
Zend_Registry::set('configSection', $configSection);
$config = new Zend_Config_Ini(ROOT_DIR . '/application/config.ini',$configSection);
Zend_Registry::set('config',$config);
date_default_timezone_set($config->date_default_timezone);
//Database configuration settings go here. :)
$db = Zend_Db::factory($config->db);
Zend_Db_Table_Abstract::setDefaultAdapter($db); …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过foreach向数组添加值,但它只返回单词"Array"而不是实际的字符串.
$msg = array();
foreach ($results as $result) {
$inventory = $result->qoh;
$inventoryOrder = $result->qo;
$product = $result->item;
$totalinv = $inventory+$inventoryOrder;
if ($inventory <= $threshold) {
$message = "Inventory for $product has fallen beneath threshold. $inventory remaining.\n";
$msg[] = array($message);
}
}
print (array_values($msg));
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方法,每次返回单词"Array"