xoops forums

sarahmx

Quite a regular
Posted on: 2007/11/24 12:55
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#1

username as uid ?

is there any module or htaccess way to replace user id with username


as example from

Quote:


Quote:

etc

Dave_L

XOOPS is my life!
Posted on: 2007/11/24 13:49
Dave_L
Dave_L (Show more)
XOOPS is my life!
Posts: 2277
Since: 2003/11/7
#2

Re: username as uid ?

That could be done with an Apache directive, in an .htaccess file, that redirects to a PHP script that handles the username-to-uid database lookup.

Or I guess if you want to do it the hard way, you could write a custom Apache handler.

I'm not sure if the subdomain reference (username.xoops.org) could be handled in this manner.

trabis

Core Developer
Posted on: 2007/11/24 15:45
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#3

Re: username as uid ?

Dave_L
Quote:
I'm not sure if the subdomain reference (username.xoops.org) could be handled in this manner.


You just need a hosting account with Dedicated IP. Then you redirect your subdomains to your domain. You should have the option for use multicard subdomains so you don´t have to create all the subdomains by hand.

Example: redirect *.yoursite.com to www.yoursite.com

Then you need a script included on your mainfile.php to read the PHPSELF and extract the subdomain name. If the there is a name (subdomain) in the URL then you match it against your users database and get the corresponding UID. Having the uid you just need to redirect the page. No need for htaccess this way. :)

trabis

Core Developer
Posted on: 2007/11/24 16:02
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#4

Re: username as uid ?

sarahmx:
Quote:

Should be careful, this way you migth get a conflict with user names and existing folders.

You should create a extra folder just for that and then follow Dave´s sugestion.

Ex: https://xoops.org/users/saramax/
Ex: https://xoops.org/blogs/the_saramax_blog/

etc,etc,

sarahmx

Quite a regular
Posted on: 2007/11/24 16:10
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#5

Re: username as uid ?

interesting....

any step by step instruction or good resource out there ? I would like to try..i'm am a beginner on this thing.....

i want to do this to all my site existing users not just my account...

trabis

Core Developer
Posted on: 2007/11/24 17:56
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#6

Re: username as uid ?

Ok, lets do it:

Create a folder in your root and name it "users":

Create a .htaccess file under the "users" folder and paste this lines:

RewriteEngine on
RewriteCond 
%{REQUEST_URI} ^(^/users/)(.*)$
RewriteRule ^([^link].*)$ https://xoops.org/users/?link=%2 [R,QSA,L]


Were "www.xoops.org" should be changed to fit your site

Create now a index.php file under the "users" folder and paste this lines:

<?php
include("../mainfile.php");
isset(
$_GET['link'])? $uname $_GET['link'] : $uname '';

if (
$uname != ''){
    
$sqlsprintf("SELECT uid FROM %s WHERE (uname = '%s')",$xoopsDB->prefix("users"), $uname);
    
$result $xoopsDB->queryF($sql);
    list(
$uid) = $xoopsDB->fetchRow($result);
    if (
$uid '0'){
        
$redirect_to XOOPS_URL.'/userinfo.php?uid='.$uid;
    } else {
        
$redirect_to XOOPS_URL.'/index.php';
    }
    
} else {
    
$redirect_to XOOPS_URL.'/index.php';
}

header('location: '.$redirect_to);
?>


OK, it will work now!

Atention: Your unames should not have special characters, spaces, etc.

sarahmx

Quite a regular
Posted on: 2007/11/25 1:43
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#7

Re: username as uid ?

impressive...i did a quick test in localhost...it works
this will be a cool feature for XOOPS if it is developed as a module

in the Friendster site...there is option for user to select their friendly url

typed
http://www.mysite.com/users/?link=admin
in the url box and it redirects to
http://www.mysite.com/userinfo.php?uid=1

hmmm i got questions
is it possible for the url to remain mysite.com/users/?link=admin
coz as soon it redirects the url change back to the origional url mysite.com/userinfo.php?uid=1

how do i redirect from userinfo.php?uid=1 to ?link=admin instead?

trabis

Core Developer
Posted on: 2007/11/25 2:25
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#8

Re: username as uid ?

Hi,
The ideia is not type
http://www.mysite.com/users/?link=admin

but
http://www.mysite.com/users/admin

you will get redirected to your userinfo the same way.

I did not understand what you want.

You don´t want your users to notice they were redirected, maintaing the "http://www.mysite.com/users/admin" in the browser?
(in this case the htaccess should be modified to point to userinfo.php and userinfo.php would have to be hacked
The R should be taken away to avoid rewriting the url:
[QSA,L]
)

Or

You want to every user links on the site to be changed to this new url?
(not shure here, guess it should require hacking a core file or all modules installed or both :( )


Yes, a module can be made to ask a url for users to choose or you can hack XOOPS by adding an extra field in their profile form, an extra field in users database and adding some lines in the users class. You can also use smartprofile for that but there must have some checkings to prevent special characteres and equal data.

trabis

Core Developer
Posted on: 2007/11/25 3:09
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#9

Re: username as uid ?

One minute please

sarahmx

Quite a regular
Posted on: 2007/11/25 4:57
sarahmx
sarahmx (Show more)
Quite a regular
Posts: 378
Since: 2007/10/28
#10

Re: username as uid ?

Thank you trabis

Quote:
I tried these two but it is not working
http://www.mysite.com/users/admin
http://www.mysite.com/users/admin/

this one works
http://www.mysite.com/users/?link=admin
which redirects to
http://www.mysite.com/userinfo.php?uid=1


Quote:

You don´t want your users to notice they were redirected, maintaing the "http://www.mysite.com/users/admin" in the browser?
(in this case the htaccess should be modified to point to userinfo.php and userinfo.php would have to be hacked
The R should be taken away to avoid rewriting the url:
[QSA,L]
)



yes..this is wat i want....
when user type in
http://www.mysite.com/users/username

it will remain
http://www.mysite.com/users/username