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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?