资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php数据接收脚本,收录php脚本

php怎么从表单接收数据

PHP 可以通过POST、GET方法获取到表单提交的数据

10年积累的成都做网站、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有莒县免费网站建设让你可以放心的选择与我们合作。

获取到的POST、GET是数组形式的值,需要通过键值来详细获取相应的值

比如: index.php 页面

下面是POST方法

form name="form1" method="post" action="index.php"

input type="text" name="contents" value=""

input type="submit" value="提交"

/form

?php

//获取表单提交的数据

$contents = $_POST['contents'];

echo $contents;

?

也可以是下面是GET方法

form name="form1" method="get" action="index.php"

input type="text" name="contents" value=""

input type="submit" value="提交"

/form

?php

//获取表单提交的数据

$contents = $_GET['contents'];

echo $contents;

?

POST相对于GET方法,更好一些,可以提交大量数据,以及更安全些。

php如何发送和接收JSON数据

对于json,PHP有对应的方法进行操作。

一般而言,json会以字符串形式传给PHP脚本,一般都是放在$_POST里面,

14

?php

// 接收

$json_parameter = $_POST['json_str'];

// 处理, 变成数组

$array = json_decode($json_parameter);

// PHP 把数组数据变成json格式字符串,发给页面

$demo = array(

'key' = 'value',

'key2' = 'value2'

);

$demo_json = json_encode($demo); // 格式是{"key":"value","key2":"value2"}

echo $demo_json;

php如何实现脚本异步执行的方法具体分析

php语言得用fsockopen()函数,实现脚本异步运行,代码如下

异步请求函数(用debug参数若为true则为用为调试,开启调试可以看到异步的执行情况,但是失去异步的效果)

main.php

?php

/**

* 异步请求

* @copyright  Copyright (c) Hangzhou Technology Co.,Ltd. ()

* @author     $Author: juny $

* @version    $Id: main.php 332 2018-09-23 09:15:08Z juny $

*/

function request_by_fsockopen($url,$post_data=array(),$debug=false){

$url_array = parse_url($url);

$hostname = $url_array['host'];

$port = isset($url_array['port'])? $url_array['port'] : 80;

@$requestPath = $url_array['path'] ."?". $url_array['query'];

$fp = fsockopen($hostname, $port, $errno, $errstr, 10);

if (!$fp) {

echo "$errstr ($errno)";

return false;

}

$method = "GET";

if(!empty($post_data)){

$method = "POST";

}

$header = "$method $requestPath HTTP/1.1\r\n";

$header.="Host: $hostname\r\n";

if(!empty($post_data)){

$_post = strval(NULL);

foreach($post_data as $k = $v){

$_post[]= $k."=".urlencode($v);//必须做url转码以防模拟post提交的数据中有符而导致post参数键值对紊乱

}

$_post = implode('', $_post);

$header .= "Content-Type: application/x-www-form-urlencoded\r\n";//POST数据

$header .= "Content-Length: ". strlen($_post) ."\r\n";//POST数据的长度

$header.="Connection: Close\r\n\r\n";//长连接关闭

$header .= $_post; //传递POST数据

}else{

$header.="Connection: Close\r\n\r\n";//长连接关闭

}

fwrite($fp, $header);

//-----------------调试代码区间-----------------

//注如果开启下面的注释,异步将不生效可是方便调试

if($debug){

$html = '';

while (!feof($fp)) {

$html.=fgets($fp);

}

echo $html;

}

//-----------------调试代码区间-----------------

fclose($fp);

}

$data=array('name'='guoyu','pwd'='123456');

$url='';

request_by_fsockopen($url,$data,true);//

other.php

?php

header("content-type:text/html;charset=utf-8");

//error_reporting(0);

//ini_set('html_errors',false);

//ini_set('display_errors',false);

$name = isset($_POST['name'])?$_POST['name']:'';

$pwd = isset($_POST['pwd'])?$_POST['pwd']:'';

echo $name.$pwd;

echo 'success ok';

die;

?

使用实例:

[运行的main.php主脚本文件]

$data=array('name'='guoyu','pwd'='123456');

$url='';

request_by_fsockopen($url,$data,true);//把应用B的用户表异步-同步数据

[导步执行文件other.php]

在other.php中便可以用$_POST接收main.php提交过来的参数,从而进行下一步操作

以上就是php如何实现脚本异步执行的方法具体分析的详细内容.

PHP怎么接收数据

三中接受方式:

$_GET    //get过来的数据

$_POST  //post过来的数据

file_get_contents("php://input")   //接口过来的xml等字符串数据用这个接

这三个方法足以接受任何数据了,具体你还要百度一下用法

php中的request数据接收

html

headtitlecalc/title/head

body

form action="calc.php" method="post"

table border="1"

tr

td colspan="4"numb1: input type="text" name="numb1" //td

/tr

tr

td colspan="4"numb2: input type="text" name="numb2" //td

/tr

tr

tdinput type="radio" name="operation" value="+" / 加/td

tdinput type="radio" name="operation" value="-" / 减/td

tdinput type="radio" name="operation" value="*" / 乘/td

tdinput type="radio" name="operation" value="/" / 除/td

/tr

tr

td colspan="4"input type="submit" value="计算" //td

/tr

/table

/form

/body

/html

--------------------------------------------------------

?php

$num1=$_POST['numb1'];

echo $num1;

$num2=$_REQUEST['numb2'];

echo $num2;

$oper=$_REQUEST['opration']; //这个变量拼写错误,应该是operatione

//没有发现你所说的下载php的情况

PHP如何接收动态数据保存并实时显示到网页上?

头部加上超时控制,但对于很多服务器无效,因为服务器输出超时很多在服务器控制,所以建议用cmd脚本方式运行此程序:

?php

set_time_limit(0); //禁用脚本超时

// Create the socket and connect

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

$connection = socket_connect($socket,'116。236。128。220', 14580);

// Write some test data to our socket

if(!socket_write($socket, "user NoCall pass -1 vers test 1.0 filter b/B* \r\n"))

{

echo("pWrite failed/p");

}

if(!file_exists('socket_log.html')){

file_put_contents('socket_log.html', 'script

var xx = setInterval(function(){ //每5秒刷新一次页面

window.location.reload();

}, 5000);

/script');

}

// Read any response from the socket

while($buffer = socket_read($socket, 64, PHP_NORMAL_READ))

{

echo json_encode($buffer); //转换为json数据输出

//记入文件

file_put_contents('socket_log.html', json_encode($buffer), FILE_APPEND);

}

echo("pDone Reading from Socket/p");

使用方法:用命令行方式运行此脚本

php script.php

脚本会一直运行到接收数据结束,并持续将收到的数据写入socket_log.html文件。

在浏览器打开socket_log.html页面,此页面会自动每5秒刷新一次,来显示最新的数据。

确保程序有权限创建及写入socket_log.html文件


网站栏目:php数据接收脚本,收录php脚本
当前网址:http://cdkjz.cn/article/dseedoi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220