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

一. 网址传递

<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. oracle强化练习之单行函数

    1.      显示dname和loc中间用-分隔 Select dname ||'-'|| loc From dept; 2.      将部门名称左填充为10位 Select lpad( dnam ...

  2. [Java 并发] Java并发编程实践 思维导图 - 第四章 对象的组合

    依据<Java并发编程实践>一书整理的思维导图. 第一部分: 第二部分:

  3. THRDTERM-----干净地结束一个线程

    THRDTERM产生两个线程.周期性地检查一个event对象.以决定要不要结束自己. #define WIN32_LEAN_AND_MEAN #include<stdio.h> #incl ...

  4. oc29--property修饰符

    // // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject /* 如果给一个属性同时提供了g ...

  5. tflearn中num_epoch含义就是针对所有样本的一次迭代

    In tensorflow get started code: import tensorflow as tf import numpy as np features = [tf.contrib.la ...

  6. SPOJ GSS 系列

    来怒做GSS系列了: GSS1:https://www.luogu.org/problemnew/show/SP1043 这题就是维护一个 sum , mx , lmx , rmx,转移时用结构体就好 ...

  7. linux下安装rabbitmq以及在spring中进行集成

    ### 一.安装erlang 1. yum install ncurses-devel 2. ./configure --prefix=/usr/local/erlang20 --without-ja ...

  8. Vue项目打包部署到apache服务器

    vue项目在开发环境下,让项目运行起来,是通过npm run dev命令,原理是在本地搭建了一个express服务器. 但是在服务器上就不是这样的,必须要通npm run build命令来对整个项目进 ...

  9. Spark2.0.2+Zeppelin0.6.2 环境搭建 初探

    0.抱怨与其他(此部分与标题没有太多联系): 首先一点想说的是版本问题,为什么标题我会写清楚版本号呢!原因就是版本不对真的很会坑人. 就在写这篇博客的同一天,我还写了另一篇,是 Hadoop2.7.3 ...

  10. ROS-URDF-建立模型

    前言:建立一个简单的urdf模型 详解请参看教程http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20w ...