Page 1 of 2

Capturing a URL

Posted: Fri Jan 16, 2004 5:35 am
by mzfp2
Hi

my website needs the functionality of faceparty.com where if a user types say :
http://www.alljammin.com/myname/

the url is captured, and myname's profile is loaded

however my host doesn't allow this so I was wondering, if I put some JavaScript code in my 404 page not found page response page to capture the url, parse it as a string and then redirect it to the appropriate profile, would that work?!

if so how is it possible to capture the url in the address bar using JavaScript? i hope it is possible!

Thanks

http://www.alljammin.com -Free funky dating and flirting

Posted: Fri Jan 16, 2004 5:37 am
by malcolmboston
lol, not related still trying to figure out away

just wanted to say nice site design

Posted: Fri Jan 16, 2004 5:39 am
by malcolmboston
all the alljamming.com/myname/ is is a folder lol they cant stop your from using a folder

now the hardest part you have to contend with is dynamically and instantly creating a folder as soon as the user register (i believe this is how faceparty does it)

Posted: Fri Jan 16, 2004 5:44 am
by mzfp2
Hi

thanks for your nice comments

yep i thought about using folders, but the problem is, it will get extremely messy coz i have about 4000 members, and i dont fancy having 1000's of folders in my root directory!

so is there a way to do it without folders?

Posted: Fri Jan 16, 2004 5:50 am
by malcolmboston
what your are wanting to do is exactly the same as what i want to do i will try and write some code in a minute but i only got notepad so expect errors (lots of them) the idea you describe is creating thousands of pages of one base template but with all the content replaced

this is easy really, i have done this with about 15 members but 2-1000000000 members, the idea is principally the same

ill right out the code now, im not gonna try to get it perfect just give you an idea

Posted: Fri Jan 16, 2004 5:56 am
by mzfp2
ok mate thanks for ya help !

Posted: Fri Jan 16, 2004 6:00 am
by malcolmboston
here goes, debug it yourself

the var that the person is trying to do must be set elsewhere if you dont know how to do this then think twice about this script

Code: Select all

<?php 
$session_start(); 
// database connection details
$host = "yourhost"; 
$user = "yourusername"; 
$password = "yourpassword"; 
$DBname = "yourdatabasename"; 
$tablename = "yourtablename"; 
//connection variables completed 
// establishing connections 
$link = mysql_connect ($host, $user, $password); 
//connection established 
//the query defined 
$query = "SELECT * 
FROM $tablename 
WHERE username = "THIS IS WHAT YOU NEED TO CHOOSE"
// select the database 
mysql_select_db($DBname); 
// query the database 
$result = mysql_query($query); 
$data = mysql_fetch_array($result, MYSQL_ASSOC); 
//check to see if the user actually exists
if (mysql_num_rows($result) >=1) { 
    print "$person exists!"; 
} else { 
    print "$person does not exist"); 
} 
exit;

/*now for redirecting, either automatically or link button there are many ways if you use automatic the above "prints are useless"
for automatic */
if (mysql_num_rows($result) >=1){
header ("www.alljamming.com/$person")
}
else
{
header ("www.alljamming.com/sorry.php")
?>
}
exit;
this is very simple and may not work at all, i dont know ive never tried doing something like this, try and do something with it yourself and take ideas from it

edit: made a typo

Posted: Fri Jan 16, 2004 6:14 am
by mzfp2
Thanks for the script

unfortunately the script is only useful for part 2 of the problem, and does not solve the problem of having to capture the url http://www.alljammin.com/person

what i'll try to do is create a custom 404 page, and try capture the url in there, this may work.

Thanks for your all your help, very much appreciated

Posted: Fri Jan 16, 2004 6:17 am
by malcolmboston
just do what i do

create one page, your base page, find some way of differentiating users from each other (username is perfect as there cant be 2 users with the same name) write an SQL query something to the effect of select * from everyones_table where username = person

this will show a persons profile, and you can use the same page for BILLIONS of different people

simple really, cant see what a custom 404 page will do at all, if you could explain it would be great

Posted: Fri Jan 16, 2004 6:20 am
by mzfp2
well if someone enters http://www.alljammin.com/person, because there is no such folder .. no script can be executed! a error page is returned, hope im making myself clear and not mumblin on!

Posted: Fri Jan 16, 2004 6:21 am
by malcolmboston
technically

Code: Select all

//the person has been set elsewhere
$person = mal

if {
blaahblah
header ("alljamming.com/$person")
}
else
{
blah blah blah etc
say you were looking at malcolmbostons profile the variable would be set with his name so when the redirect told you to go to alljamming.com/$person you would go to alljamming.com/malcolmboston

you see what i mean

this could easily be done with sessions, but they would require destroying quite often (which is easy)

Code: Select all

session_start();
session_destroy();

Posted: Fri Jan 16, 2004 6:22 am
by malcolmboston
well if my theory is incorrect the only way i think you could do this is by automating a folder creation task when people register, CRON could do this

Posted: Fri Jan 16, 2004 8:01 am
by krash_control
You can also use a .htaccess file in your root directory that will redirect something like http://www.alljammin.com/joebloggs to http://www.alljammin.com/profiles.php?=joebloggs (is that syntax right, still getting familiar with it) and your profiles.php can take the joebloggs variable and setup the page accordingly.

Then when a user subscribes/unsubscribes you can just add/delete the redirect from the .htaccess using PHP's file access functions.

To redirect from http://www.alljammin.com/joebloggs to http://www.alljammin.com/profile.php?=joebloggs enter this in your .htaccess file

Code: Select all

Redirect Permanent /joebloggs http://www.alljammin.com/profiles.php?=joebloggs
Hoep that works for ya. I don't know how to get it to redirect just to the file, only works with the full url for me.

Posted: Fri Jan 16, 2004 1:50 pm
by Dr Evil
Sorry I might have missed something:
Did you say you could not do this:

Code: Select all

<?php
echo($REQUEST_URI);
?>
to show the ULR.

Dr Evil

Posted: Fri Jan 16, 2004 1:55 pm
by jaxn
If register_globals is off (as it should be) then you cannot use:
$REQUEST_URI.

However, you can use:
$_SERVER['REQUEST_URI']

You should be able to do that in the error page.

Note: using error pages as a means to create clean urls is a bad idea. Get a different host instead.

-Jackson