Giter Club home page Giter Club logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
I have thought about how to fix the problem, but have no idea so far.

I know of no method to check validity of the url without actually connecting to 
it, and therefore generating a warning.

There is checkdnsrr() function, but it only works for dns names (so for example 
"localhost" wouldn't work).

Suppressing the error with @ isn't a good solution either, because it will 
generate the error anyway (interfering with custom error handlers).

If you (or anyone else) have any idea how to do it, please tell me.

Original comment by [email protected] on 27 Sep 2010 at 10:45

  • Changed state: Accepted

from lightopenid.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
Sorry, I don't have a good idea.

The following code handles the case of invalid domains by using gethostbynamel 
which supports both "localhost" and ip-addresses. 

But if the domain exists and there is just no webserver, it will still cause a 
silent error.

--- lightopenid.php     27 Sep 2010 17:46:37 -0000      1.5
+++ lightopenid.php     27 Sep 2010 18:32:10 -0000
@@ -148,8 +148,16 @@
             );

             $url = $url . ($params ? '?' . $params : '');
-            $headers_tmp = get_headers ($url);
-            
+
+            # connecting to server
+            if (!$this->doesServerExist($url)) {
+                return null;
+            }
+            $headers_tmp = @get_headers($url);
+            if (!isset($headers_tmp)) {
+                return null;
+            }
+
             # Parsing headers.
             $headers = array();
             foreach($headers_tmp as $header) {
@@ -225,6 +233,9 @@
         for ($i = 0; $i < 5; $i ++) {
             if ($yadis) {
                 $headers = $this->request($url, 'HEAD');
+                if (!isset($headers)) {
+                    throw new ErrorException('No servers found!');
+                }

                 $next = false;
                     if (isset($headers['x-xrds-location'])) {
@@ -602,4 +613,24 @@
         }
         return $this->getSregAttributes();
     }
+
+    /**
+     * checks if the server specified in the url exists.
+     *
+     * @param $url url to check
+     * @return true, if the server exists; false otherwise
+     */
+    function doesServerExist($url)
+    {
+        if (strpos($url, '/') === false) {
+            $server = $url;
+        } else {
+            $server = @parse_url($url, PHP_URL_HOST);
+        }
+        if ($server === false) {
+            return false;
+        }
+        $ip = gethostbynamel($server);
+        return ($ip !== false);
+    }
 }




phpunit:
<?php
require_once('lib/openid/lightopenid.php');

class LightOpenidTest extends PHPUnit_Framework_TestCase {

    public function testDoesServerExist() {
        $openid = new LightOpenID();
        $this->assertTrue($openid->doesServerExist("localhost"));
        $this->assertTrue($openid->doesServerExist("www.google.com"));
        $this->assertTrue($openid->doesServerExist("ip6-loopback"));
        $this->assertTrue($openid->doesServerExist("127.0.0.1"));
        $this->assertFalse($openid->doesServerExist("not.exists"));

        $this->assertTrue($openid->doesServerExist("http://me.yahoo.com"));
        $this->assertTrue($openid->doesServerExist("http://me.yahoo.com/"));
        $this->assertTrue($openid->doesServerExist("http://me.yahoo.com:80"));
        $this->assertTrue($openid->doesServerExist("http://me.yahoo.com:80/"));

        $this->assertFalse($openid->doesServerExist("http://not.exists"));
        $this->assertFalse($openid->doesServerExist("http://not.exists/"));
        $this->assertFalse($openid->doesServerExist("http://not.exists:80/"));
    }
}


PS: Thanks a lot for your fixes and providing lightopenid in the first place.

Original comment by [email protected] on 27 Sep 2010 at 6:36

from lightopenid.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
Thanks! I'll include the fix.

However, throwing an error after the first HEAD fails isn't correct behavior. 

From section 7.3 of the spec:
If the Yadis protocol fails [realized mostly by a HEAD request] and no valid 
XRDS document is retrieved, or no Service Elements are found in the XRDS 
document, the URL is retrieved and HTML-Based discovery SHALL be attempted.

And anyway, $headers would be set and equal to null, so that isset($headers) == 
true, and empty($headers) == true.

I would however throw an error if the server isn't found, because further 
discovery is impossible.

Original comment by [email protected] on 27 Sep 2010 at 7:09

  • Changed state: Started

from lightopenid.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
Ok, it's commited now, with some changes and unrelated bugfixes.

Also, I'm sure that you will test it, so please tell me if you find that 
everything works, so I can upload the current version as lightopenid-0.3.

Original comment by [email protected] on 27 Sep 2010 at 9:39

  • Changed state: Fixed

from lightopenid.

GoogleCodeExporter avatar GoogleCodeExporter commented on September 10, 2024
I successfully tested it with myopenid.com, delegation to myopenid.com, google 
and yahoo. And there are no more php warning on invalid domains.

Thanks a lot.

Original comment by [email protected] on 28 Sep 2010 at 6:26

from lightopenid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.