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 易优eyoucms关于二级栏目调用的问题
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上
  • ¥15 提问一个关于vscode相关的环境配置问题,就是输入中文但是显示不出来,代码在idea可以显示中文,但在vscode不行,不知道怎么配置环境
  • ¥15 netcore使用PuppeteerSharp截图
  • ¥20 这张图页头,页脚具体代码该怎么写?