doulingna9420 2019-02-25 07:39
浏览 43
已采纳

php-curl-class检查登录是否正常

I use the php-curl-class I like to check that the login data are correct. The download area is protected with htaccess and if the login data correct the download start. If the login data not correct the download don't start, but i get the HttpStatusCode 200! Her my complette code, sorry if my description not enough, but what more should explain?

$HttpStatusCode = false;
                $curl->setBasicAuthentication(user, pw);            
                if ($curl->getHttpStatusCode() !== '401') {
                    $tmpfile = $_GET['vers'];
                    $tmppath = $_GET['path'].'/';
                    $curl->download(DOWNLOAD_PATH.$tmppath.$tmpfile, function ($instance, $tmpfile) {                       
                        $save_to_path = FS_UPDATES . basename($instance->url);
                        $fh = fopen($save_to_path, 'wb');
                        stream_copy_to_stream($tmpfile, $fh);
                        fclose($fh);
                    });                 
                    $curl->close;
                } else {
                    $HttpStatusCode = true;
                }

I get all the time HttpStatusCode 200! The download only start if the login data correct. Thats okay, but how to check the login is wrong? I would very appreciate if anyone can help me, because the examples didn't help me. Thanks in advance!!

  • 写回答

1条回答 默认 最新

  • dongshuohuan5291 2019-02-26 10:52
    关注

    Okay, thanks to all for like to help. Now i find by myself the solution. ;-) It's all the time: "99.9% the bug sit in front of the computer" ;-) In this case ME!!! ;-) So here ist the solution, may be some other people need it! Now i get the "401" Status Code!

            $tmpfile = $_GET['vers'];
            $tmppath = $_GET['path'];
            $curl->setBasicAuthentication(user, pw);    
            $curl->get(DOWNLOAD_PATH.$tmppath.'/'.$tmpfile);
            $HttpStatusCode = true;
            if ($curl->getHttpStatusCode() !== '401') { $HttpStatusCode = false;
                    $curl->download(DOWNLOAD_PATH.$tmppath.'/'.$tmpfile, function ($instance, $tmpfile) {                       
                        $save_to_path = DIR_UPDATES . basename($instance->url);
                        $fh = fopen($save_to_path, 'wb');
                        stream_copy_to_stream($tmpfile, $fh);
                        fclose($fh);
                    });
                }
                $curl->close;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵