有了错误报告,甚至是最佳实践,当在PHP中取消设置变量时,你应该先检查它是否存在(在这种情况下它并不总是存在)并取消设置,或者只是取消设置它?
<?PHP
if (isset($_SESSION['signup_errors'])){
unset($_SESSION['signup_errors']);
}
// OR
unset($_SESSION['signup_errors']);
?>
Run Code Online (Sandbox Code Playgroud) 你会怎么做这个PHP switch语句?
另请注意,这些是更小的版本,我需要创建的1将添加更多的值.
版本1:
switch ($p) {
case 'home':
case '':
$current_home = 'current';
break;
case 'users.online':
case 'users.location':
case 'users.featured':
case 'users.new':
case 'users.browse':
case 'users.search':
case 'users.staff':
$current_users = 'current';
break;
case 'forum':
$current_forum = 'current';
break;
}
Run Code Online (Sandbox Code Playgroud)
版本2:
switch ($p) {
case 'home':
$current_home = 'current';
break;
case 'users.online' || 'users.location' || 'users.featured' || 'users.browse' || 'users.search' || 'users.staff':
$current_users = 'current';
break;
case 'forum':
$current_forum = 'current';
break;
}
Run Code Online (Sandbox Code Playgroud)
更新 - 测试结果
我在10,000次迭代中运行了一些速度测试,
Time1:0.0199389457703 //如果语句
Time2:0.0389049446106 …
有人可以解释使用之间的区别
define('SOMETHING', true);
Run Code Online (Sandbox Code Playgroud)
和
$SOMETHING = true;
Run Code Online (Sandbox Code Playgroud)
也许是一个或另一个之间的好处?
我在任何地方使用变量,甚至在包含在每个页面的配置类型文件中我仍然使用变量,因为我不明白为什么要使用define方法.
我刚刚阅读这篇文章关于防止快速登录尝试的基于表单的网站身份验证的权威指南.
最佳实践#1:短暂的时间延迟随着尝试失败的次数而增加,例如:
1次尝试失败=无延迟
2次尝试失败= 2秒延迟
3次尝试失败= 4秒延迟
4次尝试失败= 8秒延迟
5次尝试失败= 16秒延迟
等
DoS攻击这个方案将是非常不切实际的,但另一方面,可能具有破坏性,因为延迟会呈指数级增长.
我很好奇我如何在PHP中为我的登录系统实现这样的东西?
根据下面的代码,我用于常规的mysql,我怎么能将它转换为使用mysqli?
是否像更改**mysql _query($ sql)一样简单 ; 到mysqli _query($ sql) ; ?**
<?PHP
//in my header file that is included on every page I have this
$DB["dbName"] = "emails";
$DB["host"] = "localhost";
$DB["user"] = "root";
$DB["pass"] = "";
$link = mysql_connect($DB['host'], $DB['user'], $DB['pass']) or die("<center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".mysql_error()."'</center>");
mysql_select_db($DB['dbName']);
// end header connection part
// function from a functions file that I run a mysql query through in any page.
function executeQuery($sql) { …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何有一个可滚动的div只在Hovered时显示它的滚动条.
示例是Google图片搜索,在下图中,您可以看到左侧边栏在您将鼠标悬停在其上之后似乎无法滚动.
这可能是CSS还是需要Javascript?如果可能,可以快速举例说明如何完成这样的任务?

我读到的关于将时间转换为用户时区的地方说,最好的方法是以UTC格式存储日期和时间,然后将用户的时区偏移量添加到此时间.
如何以UTC时间存储日期?我使用MySQL DATETIME字段.
在我的PHP代码中向MySQL添加新记录时,我将使用now()插入MySQL DATETIME.
我是否需要使用不同于now()存储UTC时间的东西?
以下图中我正在处理的项目为例...蓝色背景是一个DIV,它位于另一个DIV中,它将所有侧边栏接触部分包裹在一起.为了获得Blue BG DIV圆形边界而没有间隙,因为父母边缘/填充我不得不使用负边距
margin: -9px -2px 8px -6px;
所以问题是,使用负边距或填充是不好的做法?

我在下面的图片中运行了这个例子,这是在Flash中完成的,我想知道是否有类似的影响,在图像底部有一个带有文本的透明框可以使用CSS或其他闪存?
http://www.ajaxline.com/files/imgloop.png http://www.ajaxline.com/files/imgloop.png
由于某种原因,下面的PHP代码不起作用,我无法弄清楚.
这很奇怪,file_exists似乎没有看到图像确实存在,我已经检查过以确保将一个好的文件路径插入到file_exists函数中并且它仍在执行
如果我将file_exists更改为!file_exists,它将返回存在的图像和不存在的图像
define('SITE_PATH2', 'http://localhost/');
$noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg';
$thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if (file_exists($thumb_name)) {
$img_name = $thumb_name;
}else{
$img_name = $noimg;
}
echo $img_name;
Run Code Online (Sandbox Code Playgroud) php ×6
css ×3
mysql ×2
file-exists ×1
honeypot ×1
html ×1
mysqli ×1
security ×1
throttling ×1
timezone ×1