View Full Version : Lookink for a URL redirection script that will redirect to members profile.
fmoise99
Fri 7th Sep '01, 8:13pm
This is what I would like to do.
I am looking for redirect script that will allow a user to view their profile or another users profile by using a easy to remember URL and using the vb usernames.
Example:
http://www.hostname.com/profiles/vbusername or
http://profiles.hostname.com/vbusername
redirects to -->
http://www.hostname.com/forums/member.php?action=getinfo&username=fmoise99
Thanks for the help anyone, I'm sure other members would find it usefull.
Mark Hensler
Fri 7th Sep '01, 8:40pm
I don't see anyway to do this with .htaccess So you'll have to put this into your custom PHP 404 page.
Quicky Code [untested]
<?
if (ereg("hostname.com/profiles/",$REQUEST_URI)) {
$tmp = explode("/",$REQUEST_URI);
$username = $tmp[5];
}
if (ereg("profiles.hostname.com",$REQUEST_URI)) {
$tmp = explode("/",$REQUEST_URI);
$username = $tmp[4];
}
if ($username != "") {
// make DB connection
// blah
// find $username
$query = "SELECT userid FROM user WHERE username='$username'";
$result = mysql_query($query);
if (!$result) {
echo "\n\n<!--QUERY ERROR:" . mysql_error() . "-->\n<!--QUERY:$query-->\n\n";
echo "An error occured while trying to find user.\n";
}
else if (mysql_num_rows($result) > 0) {
// redirect
header("Location: http://www.hostname.com/forums/member.php?action=getinfo&username=" . $username);
//$tmp = mysql_fetch_row($result);
//header("Location: http://www.hostname.com/forums/member.php?action=getinfo&userid=" .$tmp[0]);
}
else {
// not a user
echo "User not found\n";
}
}
?>
Remember.. do NOT print anything before a header() function.
fmoise99
Sat 8th Sep '01, 9:23pm
The code seems to work fine except for this area:
if (ereg("hostname.com/profiles/",$REQUEST_URI)) {
$tmp = explode("/",$REQUEST_URI);
$username = $tmp[5];
}
if (ereg("profiles.hostname.com",$REQUEST_URI)) {
$tmp = explode("/",$REQUEST_URI);
$username = $tmp[4];
}
The $REQUEST_URI variable seems to call the URL/path of 404 file instead of the reffered/submitted URL and $username variable remains null. The remainder of the script tested fine with test variables.
Do you have any ideas what may be causing this problem?
Thanks for the help!
Mark Hensler
Mon 10th Sep '01, 12:49am
I'm pretty sure that's the right var to use..
How are people getting to your PHP 404 page? You should have these lines in your .htaccess page:
ErrorDocument 404 /404.php
Read more here (http://httpd.apache.org/docs/mod/core.html#errordocument).
Scott MacVicar
Mon 10th Sep '01, 1:12pm
if (eregi("hostname.com/profiles/",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[2];
}
if (eregi("profiles.hostname.com",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[1];
}
try using that code
the array values were wrong, this is a breakdown of them
$tmp[0] = hostname.com
$tmp[1] = profiles
$tmp[2] = username
second method
$tmp[0] = profiles.hostname.com
$tmp[1] = username
Hopefully that should work, also using eregi instead of ereg so its case insensetive
Mark Hensler
Mon 10th Sep '01, 7:44pm
ahh...
I was expecting $REQUEST_URI to include "http://"
Sorry about that!
fmoise99
Fri 14th Sep '01, 5:56pm
I don't know what's going on. :confused:
The code is still not working for whatever reason. This is the .htaccess code that I am using.
ErrorDocument 404 http://www.islandchat.net/forums/404.php
The other way doesn't seem to work on my website. Also the username variable is still comming out empty. I tried everything. I'm not sure what I'm doing wrong.
This is the exact code that I'm using:
<?php
include("./global.php");
if (eregi("islandchat.net/members/",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[2];
}
if (eregi("members.islandchat.net",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[1];
}
if ($username != "") {
// make DB connection
// blah
// find $username
$query = "SELECT userid FROM user WHERE username='$username'";
$result = mysql_query($query);
if (!$result) {
echo "\n\n<!--QUERY ERROR:" . mysql_error() . "-->\n<!--QUERY:$query-->\n\n";
echo "An error occured while trying to find user.\n";
}
else if (mysql_num_rows($result) > 0) {
// redirect
header("Location: http://www.islandchat.net/forums/member.php?action=getinfo&username=" . $username);
//$tmp = mysql_fetch_row($result);
//header("Location: http://www.islandchat.net/forums/member.php?action=getinfo&userid=" .$tmp[0]);
}
else {
// not a user
echo "User not found\n";
}
}
?>
Mark Hensler
Fri 14th Sep '01, 6:56pm
you forgot to change:
// make DB connection
// blah
Replace the database connection information to match your database name, username, and password.
<?php
include("./global.php");
if (eregi("islandchat.net/members/",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[2];
}
if (eregi("members.islandchat.net",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[1];
}
if ($username != "") {
$DB_host = 'localhost';
$DB_username = 'my_username';
$DB_password = 'my_password';
$DB_name = 'my_database_name';
$DB_link = mysql_connect ("$DB_host", "$DB_username", "$DB_password");
if (!$DB_link || !mysql_select_db("$DB_name")) {
echo "An error occured while tryng to connect to the database.\n";
}
// find $username
$query = "SELECT userid FROM user WHERE username='$username'";
$result = mysql_query($query);
if (!$result) {
echo "\n\n<!--QUERY ERROR:" . mysql_error() . "-->\n<!--QUERY:$query-->\n\n";
echo "An error occured while trying to find user.\n";
}
else if (mysql_num_rows($result) > 0) {
// redirect
header("Location: http://www.islandchat.net/forums/member.php?action=getinfo&username=" . $username);
//$tmp = mysql_fetch_row($result);
//header("Location: http://www.islandchat.net/forums/member.php?action=getinfo&userid=" .$tmp[0]);
}
else {
// not a user
echo "User not found\n";
}
}
?>
fmoise99
Fri 14th Sep '01, 7:45pm
I made a include to global.php, but I will remove and try it that way to see what happens. I will post the results.
fmoise99
Fri 14th Sep '01, 8:14pm
I tried that and it still doesn't work. :(
Mark Hensler
Sat 15th Sep '01, 12:13am
did you change this:
$DB_host = 'localhost';
$DB_username = 'my_username';
$DB_password = 'my_password';
$DB_name = 'my_database_name';
What errors are you getting?
Scott MacVicar
Sat 15th Sep '01, 5:06am
I just realised that SCRIPT_URI doesn't hold the directory ie the /members/USERNAME part and its just the 404.php a variable for this will have to be found.
Apart from that I can go to 404.php?username=MYUSERNAME and it works for me. So the actual member find code works. I also improved it and utalised global.php
<?php
require('./global.php');
if (eregi("islandchat.net/members/",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[2];
}
if (eregi("members.islandchat.net",$HTTP_SERVER_VARS["SCRIPT_URI"])) {
$tmp = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$username = $tmp[1];
}
if ($username != "") {
// find $username
$result = $DB_site->query("SELECT userid FROM user WHERE username='$username'");
$user = $DB_site->fetch_array($result);
if ($user["userid"]) {
// redirect
header("Location: http://www.islandchat.net/forums/member.php?action=getinfo&userid=".$user["userid"]);
}
else {
// not a user
header("Location: http://www.islandchat.net/forums/");
}
}
?>
fmoise99
Sat 15th Sep '01, 3:25pm
Originally posted by Max Albert
did you change this:
$DB_host = 'localhost';
$DB_username = 'my_username';
$DB_password = 'my_password';
$DB_name = 'my_database_name';
What errors are you getting?
Yes, I did. No errors were shown. But, it would work with the argument 404.php?username=MYUSERNAME PPN stated above. That shows the redirect code works.
vBulletin® v3.8.0 Release Candidate 1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.