Hey, sorry for asking so many questions. Would have Googled this, but it's impossible to word for a search field... I'm trying to set up user profiles on my site, but can't seem to get my set up working. I'm not sure what the best method is for this but what I planned to do was place code from profile.php into all the user created php profile pages via writing to their file. work flow as follows. 1)user signs up 2)The following function is called to include the base file's code into their created php profile page. fwrite($profileFilePointer, '<' . '?php require(\'./system/files/profile.php\'); ?' . '>'); PHP: 3)All the code that I write in the base file will be interpolated on each user's profile page. -Not sure if this is the right method to go about it, but figured it would be dynamic. I'd only have to change the base file, and all the profiles would change based on the code that's in it. Please correct me if I'm wrong. The problem I'm having is some of the code in the created profile isn't working. When I go to the actual profile url for the signed up user the page loads, so some of the code is working...I get css and html fine... but other things like variables and the such don't show up. The actual variable that I'm going to chop for interpolation is $profileUserName = __FILE__; but it wouldn't show up so I made a dummy variable $UNAMER, which also didn't show up. The interpolation happens in basic info where the php tag is. profile.php (This is only part of the file, but the part where the problem is. This also the file that gets included on created pages via the write function.); <?php include('/system/scripts/phpclasses/systemclass.php'); include('/system/prime_system_data/sqlpassword.php'); $profileUserName = __FILE__; $UNAMER = "Jeremy"; ?> <div id="pagecontent"><br/> <div id="basicinfo" class="boxcontainer"> <div class="boxcontainerheader"><span id="basicinfoheadertext">Basic Info</span></div> <div class="boxcontainercontent"> <span id="basicinfoname" class="basicinfoparts">Username: <? echo "$UNAMER"; ?> </span><br/> <span id="basicinfowebsite" class="basicinfoparts">Website:</span><br/> <span id="basicinfofriends" class="basicinfoparts">Friends:</span><br/> <span id="basicinfomusic" class="basicinfoparts">Favorite Music:</span><br/> <span id="basicinfogenres" class="basicinfoparts">Favorite Genres:</span><br/> <span id="basicinfologin" class="basicinfoparts">Last Login:</span><br/> <div id="basicinfobuttonpanel"></div> </div> PHP:
Can you let me know what exactly you are building? I mean are you writing custom code? or using some framework of sorts?
I don't suggest creating a new file for each user. It'll be a mess. Save all data in a database, and pull it based on a username in a GET variable.
Hey, building everything from the ground up. Not sure how to go about this part... The reason I have a file for each user being created is so they can have their own profile url... website.com/their file name... I do plan on storing all the information in a database and hauling it out...That's why I'm using the file name as a sort of pointer for the information in database. The problem is variables that I create in the base file aren't being interpolated on the page that's written to with the file write function. Not sure what a get variable is... I'll have to look that up... ahh... do you guys see what I mean though? Not sure what the best way to go about this is.. I'll look into the get variable, but any other ideas on what I'm trying to do would be greatly appreciated.. thanks for input.
Oh Nico.. "I don't suggest creating a new file for each user. It'll be a mess." I'm not writing an entire file for each user... I've got one base file with all the code...and that code is written to one file named after their username. Then information is hauled out of the db based on the file name... Not sure if you knew that or not....
Lol, never mind about the Get variable... I wasn't thinking about post and get when I read that, lol.... ahh... I don't understand how to use get variables to do what I'm trying to do...I'm not working with forms when I try to pull the information from the database... sorry... When I think about creating profiles everything is muddled, lol... the only way I could work out how to do it is to haul information from the db based on their username, and I figured I'd get that from their profile page by processing __FILE__. lol... the problem is that the variables aren't being read on the page...ugh, lol.
Okay, I understand now what you're trying to do. I still suggest you pick another route. You can use an .htaccess file to rewrite URLs. For instance: RewriteEngine On RewriteRule ^/profile/([a-z0-9]+)$ profile.php?username=$1 Code (markup): ... would allow you to have clean URLs for each user. Eg /profile/jeremy would translate into profile.php?username=jeremy This way you don't have to create separate files, and your URLs can look even cleaner.
okay, I didn't know you could rewrite urls... This seems like it would be a harder method. I'll have to ask some questions and do some research to understand it. where would I re-direct users after they login? I suppose to their own profile... but how would I do that without a file? I don't understand the concept of having pages without files to correspond to them.
I do see what you're saying here through... I guess there would be one base file... and then from what you've written here. "profile.php?username=jeremy" The variable for username would be used to pull information from the the database... I guess my question is how does the site, or program, know which profile is trying to be accessed.... is there a way to haul variables from a typed in url to use in the pages code or something?
You would just redirect them to /profile/jeremy. "jeremy" would be passed to profile.php, in which you check if the user from the GET variable exists. profile.php <?php $username = $_GET['username']; // grab userinfo based on $username from database and display the result. ?> PHP: Just program your site to work with profile.php?username=jeremy, and after that you implement the .htaccess solution to make the URLs pretty. It's really not that difficult, and probably worth the trouble.
okay... starting to clear up, lol. I'll look into all that can be done with GET variables... I'm just missing something... I'm not sure what it is... so far in my site user signs up via a form on the front page, they go through two other forms that collect different information, and then from there I'm where I was at writing to their profile page... for this method I would cut out writing a file for each member and have the one profile file in my root directory... from there I'm blank still... I don't understand working backwards from urls...at all, lol... what if a user typed in mysite.com/jim to get to jims profile... since there's not a file called jim in my root... how do I tell my site to take that variable and send it to a page to see if this user exists, and then on to the profile page where that jim variable would be used to pull information from the database? I think that should about clear me up, lol.
Search for "url rewriting in php", you'll find good tutorials for same. Here is the top result that I found to be helpful: http://stackoverflow.com/questions/16388959/url-rewriting-with-php Basically when user types mysite.com/jim , it will actually run mysite.com/profile.php?user=jim, and then you can use $_GET['user'] for the variable that you need, and then you can use that variable to pull information from the database (for example in MySQL you'll just have to run query $query= "SELECT * FROM databasename WHERE user = ".$_GET['user'] PHP: and then you can display essential information from that entry.
Take a look at the first code I posted: RewriteRule ^/profile/([a-z0-9]+)$ profile.php?username=$1 Code (markup): The first thing after "RewriteRule" is a regular expression. ^marks the beginning of the string, then follows a slash, the word "profile", another slash, and then any string that contains letters from a-z and numbers from 0-9 (just assuming you want to allow numbers here). Since the last part is inside parenthesis, it'll be considered a "group". You can access said group later with $1 ($2 for the second group, if any, etc...). The second part, profile.php?username=$1 is your original file that'll be invisible to the user throughout the whole process. After the user singed up and submitted all details, you do nothing extra. The profile URL will already be available. It's profile.php's job to verify if the given username exists. It'll take any username you supply. No matter if it exists or not. If the user types in the URL you mentioned above, the .htaccess rewrite rule will fire and profile.php will run. Then you check from there anything that needs to be checked. The .htaccess file won't create new files. It's essentially the same as profile.php?username=jeremy. The only thing it does is pretty URLs. Nothing else.