我在PHP中使用套接字连接将数据发布到Apache Web服务器.我对这种技术有点新意,我不知道如何将标题与响应主体隔离开来.
发送代码:
<?php
// collect data to post
$postdata = array(
'hello' => 'world'
);
$postdata = http_build_query($postdata);
// open socket, send request
$fp = fsockopen('127.0.0.1', 80);
fwrite($fp, "POST /server.php HTTP/1.1\r\n");
fwrite($fp, "Host: fm1\r\n");
fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fwrite($fp, "Content-Length: ".strlen($postdata)."\r\n");
fwrite($fp, "Connection: close\r\n");
fwrite($fp, "\r\n");
fwrite($fp, $postdata);
// go through result
$result = "";
while(!feof($fp)){
$result .= fgets($fp);
}
// close
fclose($fp);
// display result
echo $result;
?>
Run Code Online (Sandbox Code Playgroud)
服务器代码:
Hello this is server. You posted:
<pre>
<?php print_r($_POST); ?> …
Run Code Online (Sandbox Code Playgroud) 假设我想存储有关客户的各种数据,因此我有两个由数据透视表链接的模型,在数据透视表中存储每个数据字段类型的客户值:
Customer {
public function datafields()
{
return $this->belongsToMany('Datafield')->withPivot('value');
}
}
Run Code Online (Sandbox Code Playgroud)
和
Datafield {
public function customers()
{
return $this->belongsToMany('Customer')->withPivot('value');
}
Run Code Online (Sandbox Code Playgroud)
所以我的表是客户,customer_datafield,datafields.
如何在客户中设置查询范围,以查找具有特定数据字段x值的所有客户?
有点像
Customer {
public function datafields()
{
return $this->belongsToMany('Datafield')->withPivot('value');
}
public function scopeSearch($query, $searchfor)
{
return $query->datafields()->pivot()
->where('value', $searchfor)
->where('datafield_id', 123);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了一些方法,但没有任何运气让人工作.任何建议非常感谢!
我试图阻止表单提交两次.我是通过捕获提交按钮的单击并在表单提交在后台继续时禁用它来实现的.
这是我正在使用的代码的一个非常基本的例子:
$("button").click(function(){
$(this).attr("disabled","true").html("Wait here while posted...");
});
Run Code Online (Sandbox Code Playgroud)
工作示例:http: //jsfiddle.net/t93Vw/
这在firefox和IE中完美运行,但在chrome中,表单未提交.为什么这种行为不同,有没有人快速解决?
apache ×1
forms ×1
http ×1
http-headers ×1
javascript ×1
jquery ×1
laravel ×1
laravel-4 ×1
php ×1