cvs: docweb /include lib_auth.inc.php /www users.php
[email protected] ("Nuno Lopes")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvsnlopess1122827306@cvsserver> |
nlopess Sun Jul 31 12:28:26 2005 EDT
Modified files:
/docweb/include lib_auth.inc.php
/docweb/www users.php
Log:
fetch the user's real name from the master server if it isnt in the DB
http://cvs.php.net/diff.php/docweb/include/lib_auth.inc.php?r1=1.8&r2=1.9&ty=u
Index: docweb/include/lib_auth.inc.php
diff -u docweb/include/lib_auth.inc.php:1.8 docweb/include/lib_auth.inc.php:1.9
--- docweb/include/lib_auth.inc.php:1.8 Fri Jul 29 17:02:54 2005
+++ docweb/include/lib_auth.inc.php Sun Jul 31 12:28:25 2005
@@ -17,7 +17,7 @@
* | Nuno Lopes <[email protected]> |
* +----------------------------------------------------------------------+
*
- * $Id: lib_auth.inc.php,v 1.8 2005/07/29 21:02:54 jacques Exp $
+ * $Id: lib_auth.inc.php,v 1.9 2005/07/31 16:28:25 nlopess Exp $
*/
require_once 'cvs-auth.inc';
@@ -108,8 +108,44 @@
*/
function user_name($user = false)
{
+ $user = $user ? $user : $GLOBALS['user'];
+
+ // first check if the name is in the DB
if ($info = user_info($user))
return $info['name'];
- return $GLOBALS['user'];;
+ //no, it isn't. fetch it from the master server
+ return master_user_name($user);
+}
+
+
+/**
+ * Fetch the user's real name from the master server
+ */
+function master_user_name($nick)
+{
+ $magic_cookie = (empty($_COOKIE['MAGIC_COOKIE']) || !ctype_alnum($_COOKIE['MAGIC_COOKIE'])) ?
+ '' : // need a generic key here!!
+ $_COOKIE['MAGIC_COOKIE'];
+
+ if (!$fp = @fsockopen('master.php.net', 80))
+ return $nick;
+
+ fputs($fp, "GET /manage/users.php?username=$nick HTTP/1.0\r\n".
+ "Host: master.php.net\r\n".
+ "Cookie: MAGIC_COOKIE=$magic_cookie\r\n".
+ "\r\n");
+
+ $txt = @fread($fp, 50000);
+ fclose($fp);
+
+ // if we found a name, cache it in the DB
+ if (preg_match('@<th[^>]+>Name:</th>\s+<td><input[^>]+value="([^"]+)"@', $txt, $match)) {
+ sqlite_exec($GLOBALS['idx'], "INSERT INTO users (username, name) VALUES ('$nick', '$match[1]')");
+ return $match[1];
+ }
+
+ return $nick;
}
+
+?>
http://cvs.php.net/diff.php/docweb/www/users.php?r1=1.3&r2=1.4&ty=u
Index: docweb/www/users.php
diff -u docweb/www/users.php:1.3 docweb/www/users.php:1.4
--- docweb/www/users.php:1.3 Sun Jul 31 11:56:11 2005
+++ docweb/www/users.php Sun Jul 31 12:28:26 2005
@@ -1,5 +1,5 @@
<?php
-/* $Id: users.php,v 1.3 2005/07/31 15:56:11 vincent Exp $ */
+/* $Id: users.php,v 1.4 2005/07/31 16:28:26 nlopess Exp $ */
include '../include/init.inc.php';
require_once '../include/lib_auth.inc.php';
@@ -11,7 +11,11 @@
exit;
}
-$info = user_info($userid);
+if (!$info = user_info($userid)) {
+ $info[ 'name' ] = master_user_name($userid);
+ $info['username'] = $userid;
+ $info['country' ] = $info['site'] = $info['wishlist'] = '';
+}
if (isset($_POST['editSubmit'])) {