我试图通过添加令牌隐藏字段来阻止用户双重提交论坛.
所以这就是我到目前为止所做的事情(在论坛加载之前我有这个代码来创建一个以当前时间为值的令牌.
$token = time();
setcookie('formToken', $token, time() + 3600);
Run Code Online (Sandbox Code Playgroud)
在我的论坛中,我有一个像这样的隐藏输入
<form method="post" action="'.$PHP_SELF.'?action=update">
<input type="hidden" name="token" value="'.$token.'" />
<input type="submit" value="go" />
</form>
Run Code Online (Sandbox Code Playgroud)
现在在我的页面顶部$ action =="update"我有这个代码
if(isset($_POST) && ($_POST['token'] != $_COOKIE['formToken'])){
$error_list .= '<li>You can not submit this forum twise.</li>';
}
Run Code Online (Sandbox Code Playgroud)
如果我点击F5刷新页面,它再次提交表单而不显示我的错误.
我在使用 SQL Server 时遇到问题,无法执行任何查询,因为托管数据库的硬盘已满。我尝试使用 MS SMS 中的“收缩”功能来收缩数据库,但由于磁盘空间已满而不起作用。
如何在不使数据库崩溃的情况下截断日志并缩小大小?
我也尝试了以下方法
USE myDatabaseName;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE myDatabaseName
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (myDatabaseName_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE myDatabaseName
SET RECOVERY FULL;
GO
Run Code Online (Sandbox Code Playgroud)
但出现以下错误
Msg 3023, Level 16, State 3, Line 2
Backup and file manipulation operations (such as ALTER DATABASE ADD FILE) on a …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHP和MySQL构建动态查询.
我所做的是创建一个表(即.field_relations)这个字段有5列
NULL)NULL)这是一个示例数据
field_name display_label table_name related_to related_to_field
account_id Account ID accounts NULL NULL
account_name Name accounts NULL NULL
first_name First Name contacts NULL NULL
last_name Last Name contacts NULL NULL
contact_id Contact ID contacts NULL NULL
account_id Account ID contacts accounts account_id
task_id Task ID tasks NULL NULL
subject Subject tasks NULL NULL
owner_id Assigned To contacts contacts contact_id
daily_sales Sales transactions accounts account_id
sold_on Sold …
我注意到 MySQL 中有一些奇怪的东西,我想知道它为什么会这样,以及有什么方法可以改变它?
设想
我有帐户 InnoDB 表,id, name, type其中包含类型为可为空的以下列。
现在,假设我有 10 条记录,其中 type = "TEST" 和 100 条记录,type IS NULL以及 20 条记录,其中 type = "STANDARD"
如果我运行这个查询
SELECT * FROM accounts WHERE type <> "TEST"
Run Code Online (Sandbox Code Playgroud)
此查询将仅向我显示 type = "STANDARD" 的 20 条记录,并忽略具有空值的 100 条记录。
要解决这个问题,我将不得不做这样的事情
SELECT * FROM accounts WHERE IFNULL(type,"") <> "TEST"
Run Code Online (Sandbox Code Playgroud)
或者
SELECT * FROM accounts WHERE (type <> "TEST" OR type IS NULL)
Run Code Online (Sandbox Code Playgroud)
NULL 值表示空白“又名无值”,无值表示 <>“TEST”
这可能是预期的行为,但我不确定为什么会这样设计
我正在尝试使用 cURL 调用与 API 进行通信。
我试图查看我发送到 API 的确切请求,“包括标题、正文和正在发布的字段”。我如何获得请求的副本?
我尝试使用,curl_getinfo但这并没有告诉我确切的请求。然后,我添加了一个代码来将请求打印到一个名为request.txt
这是我的代码,它工作正常,但没有显示正在发布的字段
function CallAPI($method, $url, $data = false, $header = array())
{
$curl = curl_init();
if(!empty($header)){
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
}
$f = fopen('request.txt', 'w');
//disable the use of cached connection
curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl, CURLOPT_FILE, $f);
curl_setopt($curl, CURLOPT_INFILESIZE, $f);
curl_setopt($curl, CURLOPT_STDERR, $f);
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data){
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
break;
case "PUT":
curl_setopt($curl, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 cURL/PHP 连接到 API。
我需要在发送 JSON 数据时为此 API 放置一个方法。
这是我的参数 $data = array('__type' => 'urn:inin.com:connection:workstationSettings');
这是我进行 cURL 调用的方式
private function _makeCall($method, $uri, $data = false, $header = NULL, &$httpRespond = array())
{
$ch = curl_init();
$url = $this->_baseURL . $uri;
if(
($method == 'POST' || $method == 'PUT')
&& $data
){
$jsonString = json_encode( $data );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $jsonString );
}
if($method == 'POST'){
curl_setopt($ch, CURLOPT_POST, true);
} elseif( $method == 'PUT'){
curl_setopt($ch, CURLOPT_PUT, true);
} else {
if …Run Code Online (Sandbox Code Playgroud) 我有一个连接器,它将使用 cURL 和 PHP 调用 RESP API。
我需要每秒调用一个方法来检查新消息,然后处理它们。我使用以下两种方法来处理消息
SetInterval():每秒调用一次 php 脚本。这工作得很好,除了我无法阻止多个SetInterval()浏览器的不同选项卡同时运行。(我不想让用户打开 10 个浏览器选项卡,这会导致一个用户SetInterval()同时运行 10 个浏览器选项卡。EventSource:一旦队列中有新数据,服务器将向浏览器发送更新。这会减慢响应时间。我对脚本的每次调用都需要大约 20 秒以上才能完成,这是一个问题。我不知道为什么会发生这种情况。这是我的SetInterval()实现
function startCalls(){
//update the screen using Intervals
refreshIntervalId = setInterval(function() {
$.getJSON("index.php", {'method': 'getMessages', 'jSON': true} , function(data){
processServerData(data);
});
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
一旦用户登录,我就会调用此函数startCalls()
在 index.php 文件内我有要调用的代码
if($method == 'getMessages'){
$messaging = new ICWS\Messaging($icws);
$messaging->processMessages();
$myQueue = $messaging->getCallsQueue();
echo json_encode($myQueue );
}
Run Code Online (Sandbox Code Playgroud)
这是我的第二个实现“服务器发送事件”
//Server Side Message Polling
function startPolling(evtSource){ …Run Code Online (Sandbox Code Playgroud) 我在Windows Server 2012上运行Apache 2.4,在端口8080上运行PHP 5.6.23.
假设我的服务器的域是"serv1.example.com"我需要运行3个Laravel实例production,staging并dev使用以下链接
serv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/dev
Run Code Online (Sandbox Code Playgroud)
我发现了另一个似乎在做同样事情的SO问题.但是当我尝试做同样的事情时,我得到以下错误
Forbidden
You don't have permission to access /dev on this server.
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的.在我的httpd-vhosts.conf文件中,我添加了以下VirtualHost
<VirtualHost *:8080>
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
DocumentRoot "C:\www\dev\public"
ServerName serv1.example.com
ServerAlias /dev
<Directory "C:\www\dev">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
然后我c:\www\dev\public\.htaccess将代码更改为以下内容
<IfModule mod_rewrite.c>
#Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d …Run Code Online (Sandbox Code Playgroud) 我正在使用 ASP.NET MVC 5 编写一个应用程序。我要存储在数据库中的所有日期时间必须首先从本地时区转换为 UTC 时区。
我不确定在请求周期内最好的地方在哪里。
我可以在控制器中通过 ViewModel 规则后将每个字段转换为 UTC。但我觉得我必须做的代码/步骤太多了。
实体框架中是否有一种方法允许我添加一条规则,在保存更改之前自动将日期时间转换为 UTC?
这是我编写的方法,它将给定的日期时间转换为 UTC
public static DateTime? ConvertToUTC(DateTime? val, TimeZoneInfo destinationTimeZone = null)
{
if (val != null)
{
var dateTimeToConvert = ConvertToDateTime(val);
if (destinationTimeZone == null)
{
if (ConfigurationManager.AppSettings["LocalTimeZone"] != null)
{
destinationTimeZone = TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]);
}
else
{
destinationTimeZone = TimeZoneInfo.FindSystemTimeZoneById(TimeZone.CurrentTimeZone.StandardName);
}
}
return TimeZoneInfo.ConvertTimeFromUtc(dateTimeToConvert, destinationTimeZone);
}
return null;
}
Run Code Online (Sandbox Code Playgroud) 我使用ASP.NET MVC 5框架编写了一个应用程序.我在视图和ViewModel之间使用双向绑定.
由于我使用双向绑定,我得到了客户端和服务器端验证的好处,这很酷.但是,当我向POST服务器发送请求,并且请求处理程序抛出异常时,我想将用户重定向到该GET方法.
当重定向发生时,我想保存模型状态,以便在显示错误时页面看起来相同.我可以使用ActionFilters和TempData 通过这种方法保存状态模型和错误.然而,当请求被重定向,从POST到GET所述模型状态被保存为System.Web.Mvc.ModelStateDictionary对象,它是一个密钥/值对与从附带的所有用户输入POST请求.
为了正确地向最终用户呈现页面,我需要将数据绑定System.Web.Mvc.ModelStateDictionary到我自己的表示模型中.
如何将System.Web.Mvc.ModelStateDictionary对象绑定到我的演示文稿对象?
这是我的代码的样子
[ImportModelStateFromTempData]
public ActionResult show(int id)
{
var prsenter = new UserProfileDetailsPresenter(id);
ModelStateDictionary tmp = TempData["Support.ModelStateTempDataTransfer"];
if(tmp != null)
{
// Some how map tmp to prsenter
}
return View(prsenter);
}
[HttpPost]
[ValidateAntiForgeryToken]
[ExportModelStateToTempData]
public ActionResult Update(int id, DetailsPresenter model)
{
try
{
if (ModelState.IsValid)
{
var updater = new UpdateAddressServiceProvider(CurrentUser);
updater.Handle(model.General); …Run Code Online (Sandbox Code Playgroud) php ×6
asp.net ×2
asp.net-mvc ×2
c# ×2
curl ×2
json ×2
mysql ×2
.htaccess ×1
apache ×1
api ×1
datetime ×1
dynamicquery ×1
icws ×1
javascript ×1
jquery ×1
laravel ×1
laravel-5 ×1
modelstate ×1
null ×1
put ×1
sql-server ×1