Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-07-2009, 02:38 PM   PM User | #1
timcalvin
New to the CF scene

 
Join Date: Aug 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
timcalvin is an unknown quantity at this point
Profile Linking

I apologize if this has been asked. I did search the forum first. First off I'm new to PHP but I'm getting a hang on it I think.

I'm trying to create a way for users of my site (which is in the works) to be able to give links to their profiles to people like this

www.mysite.com/username

Kinda like myspace does. However I don't want to create a new directory for EVERY user because I'd still like them all to use

www.mysite.com/profile.php

instead of having to create a new one for everyone, because that obviously defeats the purpose of creating a data driven site anyway, right???

Anyone know how to do this?

Thanks
Tim
timcalvin is offline   Reply With Quote
Old 08-07-2009, 02:42 PM   PM User | #2
jswany
New Coder

 
Join Date: Jul 2009
Location: UK
Posts: 72
Thanks: 5
Thanked 9 Times in 9 Posts
jswany is an unknown quantity at this point
You could use the get method.

www.mysite.com/profile.php?user=jswany

then use the following to get thier data
PHP Code:
$user mysql_real_escape_string($_GET['user']);

// then use sql to retreive thier data.
$sql "SELECT * FROM users WHERE user='$user'";
$get_details mysql_query($sql) or die (mysql_error()); 
just an idea
jswany is offline   Reply With Quote
Users who have thanked jswany for this post:
timcalvin (08-07-2009)
Old 08-07-2009, 02:47 PM   PM User | #3
timcalvin
New to the CF scene

 
Join Date: Aug 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
timcalvin is an unknown quantity at this point
Hey jswanty,

Thanks for the tip. That's how I'm assuming I'm going to be doing it, I just thought it would be cool and look better if I could leave out everything except the username.
timcalvin is offline   Reply With Quote
Old 08-07-2009, 03:00 PM   PM User | #4
jswany
New Coder

 
Join Date: Jul 2009
Location: UK
Posts: 72
Thanks: 5
Thanked 9 Times in 9 Posts
jswany is an unknown quantity at this point
well you could do
www.mysite.com/?user=jswany

and the on the index page have
PHP Code:
if(isset($_GET['user'])) {
$user mysql_real_escape_string($_GET['user']);
header("location:profile.php?user=$user");
exit;

then use the same code as before on your profile page
PHP Code:
$user mysql_real_escape_string($_GET['user']);

// then use sql to retreive thier data.
$sql "SELECT * FROM users WHERE user='$user'";
$get_details mysql_query($sql) or die (mysql_error()); 
but then that isn't much better
jswany is offline   Reply With Quote
Old 08-07-2009, 03:22 PM   PM User | #5
Zangeel
Regular Coder

 
Zangeel's Avatar
 
Join Date: Oct 2007
Location: public_html/
Posts: 638
Thanks: 17
Thanked 79 Times in 79 Posts
Zangeel will become famous soon enough
Just use mod rewrite.. In your .htaccess put something like

Code:
RewriteEngine On

RewriteRule ^([a-zA-z]+)$ profile.php?user=$1
Then site.com/username is the same as site.com/profile.php?user=username
__________________
PHP Code:
$aString is_string((string)array()) ? true false// true :D 
[/CENTER]
Zangeel is offline   Reply With Quote
Old 08-07-2009, 03:22 PM   PM User | #6
timcalvin
New to the CF scene

 
Join Date: Aug 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
timcalvin is an unknown quantity at this point
Cool... I definitely like that better... it's a step in the right direction! Good idea.
timcalvin is offline   Reply With Quote
Reply

Bookmarks

Tags
link, php, profile

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:06 AM.


Advertisement
Log in to turn off these ads.