数据传输是用户交互中最重要的环节,下面收集了几个数据传输的方法,作为记录(未测试,在使用之前需要测试,如果后面我测试了,会对已测试项进行标注)

一. 网址传递

<a href=”test.php?id=3&name=mike”>next</a>

可用 $_GET['id'] 和$_GET['name']访问GET 的数据。
二. Cookie 传递
1、 设置Cookie
简单的:

SetCookie("MyCookie", "Value of MyCookie"); 

带失效时间的:

SetCookie("WithExpire", "Expire in 1 hour", time()+3600);//3600秒=1小时

什么都有的:

SetCookie("FullCookie", "Full cookie value", time()+3600, "/forum", ".phpuser.com", 1);

如果要设置同名的多个Cookie,要用数组,方法是:

SetCookie("CookieArray[0]", "Value 1");
SetCookie("CookieArray[1]", "Value 2");

2、 接收和处理Cookie

echo $_COOKIE[‘MyCookie’];
echo $_COOKIE[‘CookieArray[0]’];
echo count($_COOKIE[‘CookieArray’]);

3、删除Cookie 
要删除一个已经存在的Cookie,有两个办法: 
一个办法是调用只带有name参数的SetCookie,那么名为这个name的Cookie 将被从关系户机上删掉;
另一个办法是设置Cookie的失效时间为time()或time()-1,那么这个Cookie在这个页面的浏览完之后就被删除了(其实是失效了)。 
要注意的是,当一个Cookie被删除时,它的值在当前页在仍然有效的。
三. Session传递
test1.php

<?
session_start();
session_register("count");
echo $count=0;
?>

test2.php

<?
session_start();
echo $count++;
?>

四.ajax post

jQuery(function($)
{
$.ajax({
type: 'post',
url: 'xxx.php',
data: strPost,
dataType: 'json',
success: function(data){
}
});
});

五.curl post

exm1:

$ch = curl_init();
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
$header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache');
curl_setopt($ch, CURLOPT_REFERER, "http://www.xxx.com");
curl_setopt($ch, CURLOPT_URL, "http://www.xxx/login/login.php");
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$strPOST = "url=/home/&email=xxx@sohu.com&password=xxx";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strPOST);
$result = curl_exec($ch);

exm2:

function cevin_http_open($url, $conf = array())
{
if(!function_exists('curl_init') or !is_array($conf)) return FALSE; $post = '';
$purl = parse_url($url); $arr = array(
'post' => FALSE,
'return' => TRUE,
'cookie' => 'C:/cookie.txt',);
$arr = array_merge($arr, $conf);
$ch = curl_init(); if($purl['scheme'] == 'https')
{
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
} curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $arr['return']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $arr['cookie']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $arr['cookie']); if($arr['post'] != FALSE)
{
curl_setopt($ch, CURL_POST, TRUE);
if(is_array($arr['post']))
{
$post = http_build_query($arr['post']);
} else {
$post = $arr['post'];
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
} $result = curl_exec($ch);
curl_close($ch); return $result;
}
$postfield="userName=test&year=2008&passWord=123456&Submit=%CC%E1%BD%BB"; //curl post的数据格式
$post = 'aa=ddd&ee=d';
echo cevin_http_open('http://localhost/ret.php',array('post'=>$postfield)); //post 过去的目标页http://localhost/ret.php

ret.php

<?php
if($_POST)
print_r($_POST);
?>

六.fsockopen post

function post($data)
{
//创建socket连接
$fp = fsockopen("www.xxx.com",80,$errno,$errstr,10) or exit($errstr."--->".$errno);
//构造post请求的头
$header = "POST /xxx.aspx HTTP/1.1\r\n";
$header .= "Host:127.0.0.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($data)."\r\n";
$header .= "Connection: Close\r\n\r\n";
//添加post的字符串
$header .= $data."\r\n";
//发送post的数据
fputs($fp,$header);
$inheader = 1;
while (!feof($fp)) {
$line = fgets($fp,128); //去除请求包的头只显示页面的返回数据
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}
if ($inheader == 0) {
$ret=$line;
}
}
fclose($fp);
return $ret;
}
$str = "Name=".urlencode($name)."&sex=".urlencode($sex)."&Age=".urlencode($age)."&Phone=".urlencode($phone)."&IDCard=".urlencode($idcard)."&Time=".urlencode($time)."&Email=".urlencode($email);
$UserID = post($str); //返回值

七.include框架

include('get.php');

来源:http://bbs.csdn.net/topics/330033219

不用form怎么post数据的更多相关文章

  1. 04: Form 验证用户数据 & 生成html

    目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...

  2. ligerui_实际项目_003:form中添加数据,表格(grid)里面显示,最后将表格(grid)里的数据提交到servlet

    实现效果: "Form"中填写数据,向本页"Grid"中添加数据,转换成Json数据提交,计算总和,Grid文本框可编辑,排序 图片效果: 总结: //disp ...

  3. winPcap_6_不用回调方法捕获数据包

    用 pcap_next_ex() 函数代替 _5_ 中的 pcap_loop()函数: pcap_loop()函数是基于回调的原理来进行数据捕获,这是一种精妙的方法,并且在某些场合中,它是一种很好的选 ...

  4. 解析form表单数据

    //解析form表单数据 function parseFormData(params) { var args = new Object(); for(var key in params){ if(!p ...

  5. django django中的HTML控件及参数传递方法 以及 HTML form 里的数据是怎么被包成http request 的?如何在浏览器里查看到这些数据?

    https://www.jb51.net/article/136738.htm django中的HTML控件及参数传递方法 下面小编就为大家分享一篇django中的HTML控件及参数传递方法,具有很好 ...

  6. VUE axios 发送 Form Data 格式数据请求

    axios 默认是 Payload 格式数据请求,但有时候后端接收参数要求必须是 Form Data 格式的,所以我们就得进行转换.Payload 和 Form Data 的主要设置是根据请求头的 C ...

  7. formset批量处理form表单数据

    Formset(表单集)是多个表单的集合.Formset在Web开发中应用很普遍,它可以让用户在同一个页面上提交多张表单,一键添加多个数据 class StudentStudyRecordModel( ...

  8. easyui form 方式提交数据

    http://ldzyz007.iteye.com/blog/2067540 <form id="ff" method="post">      . ...

  9. easyui不提交window中的form表单数据

    <form id="ff" method="post">, <div id="win" class="easyu ...

随机推荐

  1. JQuery调用WCF服务,部署在iis

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable ...

  2. C语言之基本算法40—字符串删除元音字母倒序输出

    //字符串,数组 /* ================================================================== 题目: 输入一行字符,将辅音字母按反序输出 ...

  3. 20170322js面向对象

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. 完美解决 linux sublime 中文无法输入

    感谢oschina 中几位前辈的分享 下面是我结合自己的情况所配置的具体步骤: 系统环境: ubuntu 12.10 输入法:fcitx fcitx 安装 apt-get install fcitx ...

  5. 利用expect验证主机口令

    ##########mianmi.sh############ #!/usr/bin/expect set ip [lindex $argv ] set password [lindex $argv ...

  6. 95.Extjs 表单中自定义的验证规则 VTypes

    1 Ext.onReady(function(){ Ext.QuickTips.init(); //重写 (自定义)xtype Ext.apply(Ext.form.VTypes,{ repetiti ...

  7. C++ 对象的赋值和复制 基本的

    对象的赋值 如果对一个类定义了两个或多个对象,则这些对象之间是可以进行赋值,或者说,一个对象的值可以赋值给另一个同类的对象.这里所指的值是指对象中所有数       据的成员的值.对象之间进行赋值是“ ...

  8. .net core2.0 中使用DB First

    一.新建一个控制台测试项目 1.1.添加引用 1.2.修改项目文件 1.3.添加红框的内容 <ItemGroup> <DotNetCliToolReference Include=& ...

  9. 页面中word文本框的编辑,两种方式

    大致效果图(对其中的功能可以增减): 实现方法1:调用js <link href="../../platform/js/kindeditor/themes/default/defaul ...

  10. sql--Truncate Table

    Truncate Table(截断表) 有时候需要清除一个表中的所有资料.要达到者个目的,一种方式是DROP TABLE 指令.不过这样整个表格就消失,而无法再被用了. 另一种方式是Delete不带w ...