Capturing a URL
Moderator: General Moderators
Capturing a URL
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
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
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
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
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
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
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
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
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;edit: made a typo
Last edited by malcolmboston on Fri Jan 16, 2004 6:14 am, edited 1 time in total.
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
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
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
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
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
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!
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
technically
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
//the person has been set elsewhere
$person = mal
if {
blaahblah
header ("alljamming.com/$person")
}
else
{
blah blah blah etcyou 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();-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
-
krash_control
- Forum Newbie
- Posts: 14
- Joined: Mon Jan 12, 2004 10:02 am
- Location: United Kingdom
- Contact:
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
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.
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?=joebloggsSorry I might have missed something:
Did you say you could not do this:
to show the ULR.
Dr Evil
Did you say you could not do this:
Code: Select all
<?php
echo($REQUEST_URI);
?>Dr Evil