如题
想不用form的方式post传递一个数据
这个应该怎么做
网上搜到了一些实例,但是看不太懂
能否给我写个具体点的例子,有注释的

解决方案 »

  1.   

    pakey:一. 网址传递
    <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 
    [PHP] 
    <? 
    session_start(); 
    session_register("count"); 
    echo $count=0; 
    ?> 
    [/PHP] test2.php 
    [PHP] 
    <? 
    session_start(); 
    echo $count++; 
    ?>
    [/PHP] 
      

  2.   


    form表单页面:
    <form action="create.php" method="post">
    <input type="radio" name="Type" value="only_file"/>仅上传文件
    <input type="radio" name="Type" value="html"/> 上传html<br /><br />
    <input type="submit" value="确认" />
    </form>create.php
    if($_POST){
    if(!empty($_POST["Type"])){
    $Type = $_POST["Type"];
    echo("ok");
    }
    else{
    echo("err");
    }
    }
    else{
    echo("err");
    }
      

  3.   

    如果要提交的数据量很大,还是需要FORM的POST方式发送。
      

  4.   

    1 ajax post
    jQuery(function($)
    {
    $.ajax({
     type: 'post',
     url: 'xxx.php',
     data: strPost,
     dataType: 'json',
     success: function(data){
     }
    });
    });
    2 curl post
    $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 protected]&password=xxx";
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $strPOST); 
    $result = curl_exec($ch); 
      

  5.   

    ajax可以用post,get传递值
    session 也可以传值
      

  6.   

    LZ意思是想不刷新页面就可以传数据吧? 如果是这样就用AJAX,AJAX可以在不刷新页面的前提下,更新内容。
      

  7.   

    很感谢大家
    我的意思是在前一个页面有一个值要传递到下一页
    但是我不想让在地址中看出来
    *.php
    后面不带参数
    并且不是用form进行传递现在看到了3种方法
    cookies
    session
    ajax第一种我已经掌握了
    第二种我想问下有没有传递数值大小的限制
    比如我传递的有1000个字符是否可以?
    第三种以前一直没有接触过 还是不明白 高手们能不能深入讲解下
    给出相关教程 或者实例也可以
      

  8.   

    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); //返回值
      

  9.   

    使用curl也可以,如果是保存希望同一服务器其他网站也能调用可以用cache
      

  10.   

    $fp = fsockopen("www.xxx.com",80,$errno,$errstr,10) or exit($errstr."--->".$errno); 这个有点不懂 上面意思?
      

  11.   


    打开一个sock如果失败就exit
      

  12.   

    可以使用 AJAX 来POST数据。
      

  13.   

    上面说的都差不多啦。
    1.用ajax post数据
    2.用fsockopen post 数据
    3.用curl post 数据
    我在这里加一个用curl的吧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
      

  14.   

    ret.php页面是这样写的,
    <PRE>
    <?php
    if($_POST)
    print_r($_POST);
    ?>
    </PRE>