1
sarahmx
username as uid ?
  • 2007/11/24 12:55

  • sarahmx

  • Quite a regular

  • Posts: 381

  • Since: 2007/10/28


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


as example from

Quote:

https://xoops.org/userinfo.php?uid=66091
to
https://xoops.org/userinfo.php?uid=sarahmx



Quote:

https://xoops.org/userinfo.php?uid=66091
to
https://xoops.org/sarahmx/
http://sarahmx.xoops.org


etc

2
Dave_L
Re: username as uid ?
  • 2007/11/24 13:49

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


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.

3
trabis
Re: username as uid ?
  • 2007/11/24 15:45

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


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. :)

4
trabis
Re: username as uid ?
  • 2007/11/24 16:02

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


sarahmx:
Quote:

https://xoops.org/sarahmx/


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,

5
sarahmx
Re: username as uid ?
  • 2007/11/24 16:10

  • sarahmx

  • Quite a regular

  • Posts: 381

  • Since: 2007/10/28


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...

6
trabis
Re: username as uid ?
  • 2007/11/24 17:56

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


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.

7
sarahmx
Re: username as uid ?
  • 2007/11/25 1:43

  • sarahmx

  • Quite a regular

  • Posts: 381

  • Since: 2007/10/28


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?

8
trabis
Re: username as uid ?
  • 2007/11/25 2:25

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


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.

9
trabis
Re: username as uid ?
  • 2007/11/25 3:09

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


One minute please

10
sarahmx
Re: username as uid ?
  • 2007/11/25 4:57

  • sarahmx

  • Quite a regular

  • Posts: 381

  • Since: 2007/10/28


Thank you trabis

Quote:

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

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

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

Login

Who's Online

193 user(s) are online (121 user(s) are browsing Support Forums)


Members: 0


Guests: 193


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits