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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来