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
https://forums.phpfreaks.com/topic/115278-solved-myspace-type-solution/
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 );

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.