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 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突