Comments (5)
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.
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.
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.
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.
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)
- version 0.5 example works but not version 0.6 HOT 3
- Ax/SReg Params may be unsigned
- LightOpenId constructor fails when trusted root URL is less than 8 chars
- Problem with curl request on a server
- Missing: A License File HOT 2
- add composer support HOT 1
- wrong mimetype check in openid.php ? HOT 3
- Use Steam as provider HOT 1
- #-comments HOT 6
- returning clamed_id is a wrong approach HOT 5
- magic get/set methods HOT 3
- LightOpenID magic properties do not work with Twig template engine due to lack of __isset
- New release HOT 1
- keep waiting for localhost HOT 2
- Validation fails when there are accent in the required variable HOT 2
- Yahoo OpenID not working on newer versions of PHP/cURL [patch proposed]
- The regular expressions in htmlTag parse some valid responses incorrectly
- Support for OpenID Connect? HOT 1
- How to select eid applet language ?
- Unregistered domain error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightopenid.