Jump to content

[SOLVED] Myspace type solution


RottenBananas

Recommended Posts

Hey guys,

 

I decided to finally learn php. I asked a friend to gimme a project that would involve a little bit of everything. He told me to make a simple version of myspace. So heres what i'm stumped about.

 

I have my login and everything setup. So a user can setup their profile and view it once they are logged in (using sessions).

 

I want to make it so that anyone can view their page i.e by going to mysite.com/usernameX you would see the usernameX's profile without you having to be logged in. Sorry If I sound vague Im a true newbie.

 

If you guys know how myspace works thats what im looking for. You register, setup your profile, and then anyone can see it by going to myspace.com/username.

 

Thanks for the help!

Link to comment
Share on other sites

Well, you'd have to use mod_rewrite ( apache feature ) to get the /username idea going on

 

buy mydomain.com/profile.php?user=myUserName is pretty much what you want to accomplish.

 

profile.php


# mysql connction stuff here

if ( !isset($_GET['user']) )
   exit( 'No profile to display' );

$q = "SELECT `profile`, `info` FROM `users` WHERE `username` = '" . mysql_real_escape_string( $_GET['user'] ) . "'";
$r = mysql_query( $q );
if ( mysql_num_rows($r) < 1 )
   exit( 'User not found' );

$profile = mysql_fetch_assoc( $r );

# profile page goes here
print_r( $profile );

Link to comment
Share on other sites

Ready for the complicated, in depth, difficult code to accomplish this task? It goes like this:

 

you will have a file in your main directory called '.htaccess'(just that, no more no less). Open it in an editor, and add the following lines:

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ viewprofile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ viewprofile.php?user=$1

 

Granted, viewprofile.php and the $_GET['user'] variable needs to be replaced with whatever page you have that views the user's profile

Link to comment
Share on other sites

Hey thanks for the reply,

I kinda get it but confused on how to code it.

 

So far I have a home.php, profilecp.php and profile.php

home is the page shown after the user logs in with links to profile and update profile(profilecp.php)

 

the profilecp.php updates the database with the users entries. so I know how to fetch from the database under this users session ID in profile.php

but I guess the whole point is to not use sessions on profile.php since i want the profiles to be public....Im confused

 

Anyone get me?

 

P.S this isnt a live site...just doing it to learn php, its on my localhost...so im assuming i have to create .htaccess myself and stick it in the same directory as the rest of my files?

Link to comment
Share on other sites

nevermind I figured it out

 

using $sql="SELECT * from `users` WHERE `username`='".$_GET['username']."'";

 

Thanks alot guys!

 

sorry, had I been to the site earlier, I would've expound on my post by explaining what you figured out. But I feel it's better that you figured it out since we won't be here all the time.. I learned by hours of troubleshooting

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.