使用PDO时,持久连接管理背后的规则/逻辑是什么?
网络服务器
DB服务器
非持久连接
<?php
// Open a new connection
// Session created in Oracle
$dbh = new PDO('DSN', 'webuser', 'password');
// webuser is active in v$session with a SID=1
$dbh = NULL;
// webuser removed from v$session
// Manually calling $dbh = NULL; will remove the session from v$session
// OR
// Wait for script EOL so a …Run Code Online (Sandbox Code Playgroud) 我需要在PHP中向Datetime对象添加一个微秒.我试图在日期时间间隔内添加一段时间,但它不起作用.
$date = new Datetime('2018-06-05 09:06:46.7487');
$date->add(new DateInterval('PT0.00001S'));
echo $date->format('Y-m-d H:i:s.u');
Run Code Online (Sandbox Code Playgroud)
虽然我认为它应该很简单,但我无法完成它.如何将一秒的分数添加到日期时间?
CodeIgniters的安全类直接操纵您的Globals $_POST,它会发现file()并file ()成为威胁,因此HTML会对其进行编码.
// config.php from my apps folder is the culprit
$config['global_xss_filtering'] = TRUE;
Run Code Online (Sandbox Code Playgroud)
自己动手(少数人,勇敢者)
在CodeIgniter 2.1.4中,转到system/core/security.php#430-442行:
/*
* Sanitize naughty scripting elements
*
* Similar to above, only instead of looking for
* tags it looks for PHP and JavaScript commands
* that are disallowed. Rather than removing the
* code, it simply converts the parenthesis to entities
* rendering the code un-executable.
*
* For example: …Run Code Online (Sandbox Code Playgroud) 我只是搞乱了,我遇到了这个:
不行
<?php
namespace first{
include 'data:text/plain, <?php function a_func(){echo "hi";}';
a_func();
}
namespace second{
include 'data:text/plain, <?php function a_func(){echo "bye";}';
a_func();
}
Run Code Online (Sandbox Code Playgroud)
[29-Apr-2016 14:12:42 America/New_York] PHP致命错误:无法重新声明a_func()(之前在数据中声明:text/plain,<?php function a_func(){echo"hi";}:1 )数据:text/plain,<?php function a_func(){echo"bye";}在第1行
不行
<?php
namespace first{
eval('function a_func(){echo "hi";}');
a_func();
}
namespace second{
eval('function a_func(){echo "bye";}');
a_func();
}
Run Code Online (Sandbox Code Playgroud)
[2016年4月29日14:19:21 America/New_York] PHP致命错误:无法重新声明a_func()(之前在C:\ path\test.php(3)声明:eval()'代码:1)in C:\ path\test.php(7):第1行的eval()代码
作品
<?php
namespace first{
function a_func(){echo "hi";}
a_func();
}
namespace second{
function a_func(){echo "bye";}
a_func();
}
Run Code Online (Sandbox Code Playgroud)
在PHP 5.6.20和7.0.5中测试
这是一个错误吗?特征?有目的地实施?
额外的功劳:我如何制作include()或eval()工作?
Windows 7 x64
PHP 7.2.2 x64
Run Code Online (Sandbox Code Playgroud)
我正在尝试查看简单的请求有效负载,因此我已经按照https://docstore.mik.ua/orelly/webprog/pcook/ch11_07.htm创建了一个PHP文件
<?php
$c = curl_init('https://www.google.com');
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, 'monkey=uncle&rhino=aunt');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);
Run Code Online (Sandbox Code Playgroud)
但与示例不同,该示例表明我可以期望得到类似以下内容,但我绝对没有输出:
* Connected to www.example.com (10.1.1.1)
> POST /submit.php HTTP/1.1
Host: www.example.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Content-Length: 23
Content-Type: application/x-www-form-urlencoded
monkey=uncle&rhino=aunt* Connection #0 left intact
* Closing connection #0
Run Code Online (Sandbox Code Playgroud)
$page 包含一个Google 404页面,所以我知道请求成功了。
有人知道我是否需要解决其他设置,或者我做错了什么?我特别对有效载荷的主体感兴趣。
是的,我知道Google卷曲并不是特别有用;我试图使这个简单的示例正常工作,以便我可以调试神秘地失败的API交互。
根据评论请求进行更新
我不能做,curl -v但是print_r( curl_version() );会产生:
Array
(
[version_number] => …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个XML文件.但坚持错误.我包括代码和错误.提前致谢.
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("comrade") or die(mysql_error());
$data = mysql_query("SELECT * FROM support WHERE DATE(`date`) = CURDATE()")
or die(mysql_error());
$xml = new SimpleXMLElement('<xml/>');
while($info = mysql_fetch_array( $data ))
{
$support = $xml->addChild('support');
$support->addChild('cus_name',$info['com_name']);
$support->addChild('ser_type',$info['ser_type']);
}
Header('Content-type: text/xml');
print($xml->asXML());
?>
Run Code Online (Sandbox Code Playgroud)
它显示以下错误
Below is a rendering of the page up to the first error.
Run Code Online (Sandbox Code Playgroud) 我是正则表达式和打字稿的新手,并试图让正则表达式匹配:
1. must start with alphanumeric (repeating is fine)
2. can contain alphanumeric (repeating is fine)
3. can contain periods, underscores, and/or hyphens (no repeating)
4. must end with alphanumeric (repeating is fine)
Run Code Online (Sandbox Code Playgroud)
我一直在搜索,发现了许多类似的示例,我尝试调整它们以根据需要工作,但是我一直无法找到正确的解决方案。如果有人有一个很好的正则表达式来帮助和一些解释为什么这样我可以了解更多关于这个很棒的系统。
以下是我试图验证为可接受字符串的一些示例:
this.is.Valid
also_a_valid_1
Me-too.im_an-ugly.but_vALid-5tring
Run Code Online (Sandbox Code Playgroud)
以及我当前的正则表达式允许的无效字符串的一些示例,但应该会失败,因为它有重复的句点/连字符/下划线,并且在开头和结尾都有句点、连字符、下划线:
-this..should..not.be.valid....
..THIS__.-also-should..fail-
why..IS_regex--so.confusing-for-n0obs
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的正则表达式示例:
validateString(myString: string): boolean {
return (/^[a-zA-Z0-9_\-\.]+((\.-?|-\.?)[a-zA-Z0-9_\-\.]+)*$/.test(varKey))
}
Run Code Online (Sandbox Code Playgroud) 我经常不会感到难过,但我现在只是在失言.
使用Chrome 37.0.2062.120 m
有人可以向我解释为什么我console.log();会报告这些结果吗?
JS代码
var some_obj = {min:1};
var another_obj = {};
console.log(some_obj);
another_obj['sometarget'] = some_obj; // <- What is this sorcery?!?!?
another_obj['sometarget']['required'] = true;
console.log(some_obj);
Run Code Online (Sandbox Code Playgroud)
console.log()输出
Object {min: 1}
Object {min: 1, required: true}
Run Code Online (Sandbox Code Playgroud)
的jsfiddle
这里我用下划线替换空格,但我无法用空格替换下划线。
import re
def repl(string):
pattern = re.compile(' ')
match = pattern.search(string)
new_str = pattern.sub('_', string)
print(new_str)
repl('But I want_to bring_out something_that we_are back to stay.')
Run Code Online (Sandbox Code Playgroud)
输出 :But_I_want_to_bring_out_something_that_we_are_back_to_stay.
我运行下面的代码,并知道这是可疑的peice,因为我已经在它上面和下面放置了一个回声.第一个运行良好,但第二个没有.
如果我将查询更改为"show tables"之类的内容,它将会运行,但如果出现任何问题,我无法查看.我检查了保留字和语法.我错过了一些明显的东西!
try
{
$sth = $dbh->prepare('SELECT COUNT(*) AS val FROM users WHERE username=:user');
$sth->binvalue('user',$_POST['user']);
$sth->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud) php ×7
regex ×2
codeigniter ×1
curl ×1
datetime ×1
forms ×1
function ×1
html-encode ×1
javascript ×1
namespaces ×1
object ×1
oracle ×1
oracle10g ×1
pdo ×1
php-7.0 ×1
python ×1
response ×1
scope ×1
string ×1
typescript ×1
windows ×1
xml ×1
xss ×1