• Private URL to members profile 1 0 5 1
Currently:  

Author Topic: Private URL to members profile  (Read 147789 times)

0 Members and 2 Guests are viewing this topic.

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Private URL to members profile
« on: May 15, 2005, 07:59:37 AM »
version 1.1

Everything what is needed is:
config.php - from 4images
.htaccess file (must be in folder where who.php will be)
who.php (you can name it how you want)

now no test needed, just set your url and try it. I`ve tested it only on my server.
will work only with this link http://your_url/who/user name
not with http://your_url/who/user name/


.htaccess

Code: [Select]
<files *>
Options MultiViews
</files>

who.php

Code: [Select]
<?
// Settings
///////////////////////////////////////////

$url = "http://www.pramoga.net";
$table = "4images_users"; //do not edit if you have not changed table prefix

// Code
///////////////////////////////////////////

include "config.php";
$a_url = $_SERVER["REQUEST_URI"];
$i = explode("/", $a_url);
$b = count($i);
$b = $b-1;
$i = str_replace(array("%20"), " ", $i[$b]);
if (($i != "") and ($i != "guest"))
{
$db = mysql_connect("$db_host", "$db_user", "$db_password") or die ("Error");
@mysql_select_db("$db_name", $db) or die ("DB not found");
$result = mysql_query("SELECT user_id FROM `$table` WHERE user_name='$i'");
$row = mysql_fetch_array($result);
$id = $row['user_id'];
header("Location: ".$url."/member.php?action=showprofile&user_id=".$id."");
}
else
{
header("Location: ".$url."");
}
?>


version 1

Just a little script that I made for my site :)
A personal addres for users, to profile.

DEMO: http://www.pramoga.net/who/admin/ (admin is user name, existing in 4images gallery)

So, first I want to explain how it works :)
"who" is not a folder, it`s originaly a script called who.php, to use this script without extension .php you will need to put .htaccess file into the folder where who.php is. The code of .htaccess is:

Code: [Select]
<files *>
Options MultiViews
</files>

So the first thing is done :)
Second is very important for script who.php and it depends on your url, how many slashes "/" there is. I made a little test to find out what number for variables you will need.

test.php
Code: [Select]
<?
$url = "http://www.pramoga.net"; //your url
$url_extender = $_SERVER["REQUEST_URI"];
$all_url = $url.$url_extender;
print_r(explode("/", $all_url));
?>

Change url in this script and go to it like that
http://www.pramoga.net/test/admin (can be another user name)
or
http://www.pramoga.net/test.php/admin (can be another user name)

DEMO: http://www.pramoga.net/test/admin
We need a number of user name, So we take it from here
Array (
  • => http: [1] => [2] => www.pramoga.net [3] => test.php [4] => admin )
    The number is 4

    We can go to final step :)

    Script who.php
    Code: [Select]
    <?
    /////////////////////////////////////////////
    // Originaly made for http://www.pramoga.net
    // If you made any modifications, feel free
    // to contact with me and share your code ;)
    /////////////////////////////////////////////

    $url = "http://www.pramoga.net";

    /////////////////////////////////////////////
    include "config.php";
    $url_extender = $_SERVER["REQUEST_URI"]; // gets url end
    $all_url = $url.$url_extender; // i dont know why, but i make all url...
    $i = explode("/", $all_url); // then I delete all slashes
    $i = $i[4]; // when I get array of symbols, I take fourth symbol (it depends on url)
    $i = str_replace(array("%20"), " ", $i); // replaces %20 with simple space " "
    if (($i != "") and ($i != "guest")) //if url is with name and it`s not guest
    {
    $db = mysql_connect("$db_host", "$db_user", "$db_password") or die ("Error"); // connecting to db
    @mysql_select_db("$db_name", $db) or die ("DB not found"); // selecting db
    $result = mysql_query("SELECT user_id FROM `4images_users` WHERE user_name='$i'"); //querying mysql, and selecting users id from db
    $row = mysql_fetch_array($result);
    $id = $row['user_id']; //selected id seting to variable $id
    //finally
    header("Location: ".$url."/member.php?action=showprofile&user_id=".$id.""); //setting header location to members profile
    }
    else //if no name was given
    {
    header("Location: ".$url.""); //setting header location to index page
    }
    // thats all :)
    ?>

    Find
    Code: [Select]
    $i[4]; and change 4 to your number, that you find in test.php :)

    It`s explained step by step, so it`s very simple :)
    Upload it to the server and try :)
Again this addres?!
http://www.funny.lt

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: Private URL to members profile
« Reply #1 on: May 17, 2005, 08:04:17 PM »
A little corection if somebody uses this plugin :)
A bug when user name contains spaces,
So add this code

Code: [Select]
$i = str_replace(array("%20"), " ", $i);
after this line

Code: [Select]
$i = $i[4]; // when I get array of symbols, I take fourth symbol (it depends on url)
more symbols can be added for replacing, by editing this array("%20","symbol","symbol","symbol")
Again this addres?!
http://www.funny.lt

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Private URL to members profile
« Reply #2 on: May 18, 2005, 03:23:57 AM »
who do i make the .htaccess file? with the Notepad?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Private URL to members profile
« Reply #3 on: May 18, 2005, 03:31:12 AM »
yes, any text editors.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Private URL to members profile
« Reply #4 on: May 18, 2005, 03:54:48 AM »
ok i did it i create the .htaccess and i run the test and i got the number 5 but when I point to /who/admin it goes to my home page :S

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: Private URL to members profile
« Reply #5 on: May 18, 2005, 05:10:46 AM »
This code shows your browser to go to the homepage
Code: [Select]
else //if no name was given
{
header("Location: ".$url.""); //setting header location to index page
}

This code is active only when this code is true

Code: [Select]
if (($i != "") and ($i != "guest")) //if url is with name and it`s not guest
if no name was given or name was "guest"
Again this addres?!
http://www.funny.lt

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Private URL to members profile
« Reply #6 on: May 18, 2005, 03:46:41 PM »
so do i have to modify someything?

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: Private URL to members profile
« Reply #7 on: May 18, 2005, 03:50:38 PM »
can you give me a link?
Again this addres?!
http://www.funny.lt

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Private URL to members profile
« Reply #8 on: May 18, 2005, 05:25:18 PM »

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: Private URL to members profile
« Reply #9 on: May 18, 2005, 05:38:16 PM »
If it is not dificult to you
comment line
Code: [Select]
header("Location: ".$url.""); //setting header location to index page and write a line after
Code: [Select]
echo $i,"<br>";
echo $all_url;

its strange... and i cant say what happened so i need to view these variables.
Again this addres?!
http://www.funny.lt

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Private URL to members profile
« Reply #10 on: May 19, 2005, 01:00:09 AM »
actualy for best result in debugin mod_rewrite is use this:
Code: [Select]
if ($user_info['user_level'] == ADMIN)
{
  echo "<pre>GET:<br>";
  print_r($_GET);
  echo "<br><br>Query string:<br>";
  echo "<b>".$_SERVER["QUERY_STRING"]."</b>";
  echo "<br><br>Redirect query string:<br>";
  echo "<b>".$_SERVER["REDIRECT_QUERY_STRING"]."</b>";
  echo "</pre>";
}
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: Private URL to members profile
« Reply #11 on: May 19, 2005, 12:29:24 PM »
try version 1.1 :) I`ve made some modifications, now you wont need any tests
Again this addres?!
http://www.funny.lt

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Private URL to members profile
« Reply #12 on: May 20, 2005, 06:44:18 PM »
I try the new version and it does not work :(:(
http://www.girlsandgirls.net/who/admin

Code: [Select]
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bhfqyruw/public_html/who.php on line 21

Warning: Cannot modify header information - headers already sent by (output started at /home/bhfqyruw/public_html/who.php:21) in /home/bhfqyruw/public_html/who.php on line 23

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: Private URL to members profile
« Reply #13 on: May 20, 2005, 06:51:07 PM »
maybe your table prefix is not "4images_" ?
Again this addres?!
http://www.funny.lt

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Private URL to members profile
« Reply #14 on: May 20, 2005, 07:42:46 PM »
yeah is girls_