thinkphp post添加参数吗

thinkphp post添加参数吗,第1张

post 在thinkphp里面可以使用 I方法获取

正如你所见到的一样,I方法是ThinkPHP众多单字母函数中的新成员,其命名来自于英文Input(输入),主要用于更加方便和安全的获取系统输入变量,可以用于任何地方,用法格式如下:

I('变量类型.变量名',['默认值'],['过滤方法'])

变量类型是指请求方式或者输入类型,包括:变量类型含义

get    获取GET参数    

post    获取POST参数    

param    自动判断请求类型获取GET、POST或者PUT参数    

request    获取REQUEST 参数    

put    获取PUT 参数    

session    获取 $_SESSION 参数    

cookie    获取 $_COOKIE 参数    

server    获取 $_SERVER 参数    

globals    获取 $GLOBALS参数    

注意:变量类型不区分大小写。

变量名则严格区分大小写。

默认值和过滤方法均属于可选参数。

function useCURL_Post( $url, $post_param = Array(), $TimeOUT = 45, $DataType = '' )

{

    $curl = curl_init()

    curl_setopt($curl, CURLOPT_URL              , $url          )

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER   , FALSE         )

    curl_setopt($curl, CURLOPT_ENCODING         , ""            )

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION   , 1             )

    curl_setopt($curl, CURLOPT_AUTOREFERER      , 1             )

    curl_setopt($curl, CURLOPT_POST             , TRUE          )

    curl_setopt($curl, CURLOPT_POSTFIELDS       , $post_param   )

    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT   , $TimeOUT      )

    curl_setopt($curl, CURLOPT_TIMEOUT          , $TimeOUT      )

    curl_setopt($curl, CURLOPT_RETURNTRANSFER   , 1             )

    if( $DataType == 'json' )

    {

        curl_setopt($curl, CURLOPT_HTTPHEADER, Array( 'Content-Type: application/json', 'Content-Length: ' . strlen( $post_param ) ) )

    }

    else

    {

        curl_setopt($curl, CURLOPT_HEADER, 0)

    }

    $data['content'] = curl_exec($curl)

    $data['error'] = curl_error($curl)

    $data['info'] = curl_getinfo($curl)

    curl_close($curl)

    return $data

}

function useCURL_Get( $url, $TimeOUT = 45, $Headers = Array() )

{

    $curl = curl_init()

    curl_setopt($curl, CURLOPT_URL              , $url          )

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER   , FALSE         )

    curl_setopt($curl, CURLOPT_ENCODING         , ""            )

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION   , 1             )

    curl_setopt($curl, CURLOPT_AUTOREFERER      , 1             )

    curl_setopt($curl, CURLOPT_HTTPGET          , 1             )

    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT   , $TimeOUT      )

    curl_setopt($curl, CURLOPT_TIMEOUT          , $TimeOUT      )

    curl_setopt($curl, CURLOPT_HEADER           , 0             )

    curl_setopt($curl, CURLOPT_RETURNTRANSFER   , 1             )

    if( $Headers )

    {

        curl_setopt($curl, CURLOPT_HTTPHEADER   , $Headers      )

    }

    $data['content'] = curl_exec($curl)

    $data['error'] = curl_error($curl)

    $data['info'] = curl_getinfo($curl)

    curl_close($curl)

    return $data

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11364247.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存