Recommended resources for video tutorials on implementing mobile phone home location query in PHP

黄舟
Release: 2023-03-15 15:56:01
Original
1390 people have browsed it

Nowadays, various WEB applications emerge in endlessly. As a programmer, how can you not have a skill to defend yourself? "Video Tutorial on Implementing Mobile Phone Location Query with PHP" will lead you to develop a complete WEB application from scratch, from framework structure to process analysis to data caching. I believe that after studying this course, you will gain more than just learning how to develop. an application.

Recommended resources for video tutorials on implementing mobile phone home location query in PHP

Course playback address: http://www.php.cn/course/412.html

The teacher’s teaching style:

The teacher’s lectures are vivid, witty, witty, and touching. A vivid metaphor is like the finishing touch, opening the door to wisdom for students; a well-placed humor brings a knowing smile to students, like drinking a glass of mellow wine, giving people aftertaste and nostalgia; a philosopher's aphorisms, cultural references Proverbs are interspersed from time to time in the narration, giving people thinking and warning.

The more difficult part in this video is the API request data:

Method 1 (if it is the post method, it only applies to one-dimensional arrays)

/**
     * curl发送htpp请求
     * 可以发送https,http,get方式,post方式,post数据发送
     */
    public function dataRequest($url,$https=true,$method='get',$data=null)
    {
        //初始化curl
        $ch = curl_init($url);
        //字符串不直接输出,进行一个变量的存储
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //https请求
        if ($https === true) {
            //确保https请求能够请求成功
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
            curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
        }
        //post请求
        if ($method == 'post') {
            curl_setopt($ch,CURLOPT_POST,true);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        }
        //发送请求
        $str = curl_exec($ch);
        $aStatus = curl_getinfo($ch);
        //关闭连接
        curl_close($ch);
        if(intval($aStatus["http_code"])==200){
            return json_decode($str);
        }else{
            return false;
        }
    }
Copy after login

Method 2 (if the post method is used, suitable for two-dimensional arrays)

/**
 * @Purpose      :  curl发送htpp请求,可以发送https,http,get方式,post方式,post数据发送
 * @Author       :  Chrdai
 * @Method Name  :  SendDataByCurl()
 * @parameter    :  string  $url     传送的 url
 *                  boolean $https   是否使用 https
 *                  string  $method  传递方法
 *                  array   $data    数据
 * @return       :  成功返回对方返回的结果,是非返回 false
 */
function SendDataByCurl($url,$https=true,$method='get',$data=null)
{
    // 初始化curl
    $ch = curl_init($url);
    // 字符串不直接输出,进行一个变量的存储
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // https请求
    if ($https === true) {
        // 确保https请求能够请求成功
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
    }
    // post请求
    if ($method == 'post') {
        curl_setopt($ch,CURLOPT_POST,true);
        // 所需传的数组用http_bulid_query()函数处理一下,就可以传递二维数组了
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    }
    // 发送请求
    $str = curl_exec($ch);
    $aStatus = curl_getinfo($ch);
    // 关闭连接
    curl_close($ch);
    if(intval($aStatus["http_code"])==200){
        return json_decode($str);
    }else{
        return false;
    }
}
Copy after login

Method 3 (if the post method is used, suitable for passing json)

/**
 * @Purpose      :  curl发送htpp请求,可以发送https,http,get方式,post方式,post数据发送
 * @Author       :  Chrdai
 * @Method Name  :  SendDataByCurl()
 * @parameter    :  string  $url     传送的 url
 *                  boolean $https   是否使用 https
 *                  string  $method  传递方法
 *                  array   $jsonStr 需要传递的 json 字符串
 * @return       :  成功返回对方返回的结果,是非返回 false
 */
function SendDataByCurl($url,$https=true,$method='get',$jsonStr=null)
{
    // 初始化curl
    $ch = curl_init($url);
    // 字符串不直接输出,进行一个变量的存储
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // https请求
    if ($https === true) {
        // 确保https请求能够请求成功
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
    }
    // post请求
    if ($method == 'post') {
        curl_setopt($ch,CURLOPT_POST,true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
        // 只需要用个 http 头就能传递 json 啦!
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length: ' . strlen($jsonStr)
            )
        );
    }
    // 发送请求
    $str = curl_exec($ch);
    $aStatus = curl_getinfo($ch);
    // 关闭连接
    curl_close($ch);
    if(intval($aStatus["http_code"])==200){
        return json_decode($str);
    }else{
        return false;
    }
}
Copy after login

The above is the detailed content of Recommended resources for video tutorials on implementing mobile phone home location query in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template