Jump to content

Member Profile and structuring URL's


doubledee

Recommended Posts

I could use some advice on how to structure my Member Profiles and their respective URLs?!

 

Right now I have a simple "profile.php" page, however I am adding to it so it has the 3 Tabs:

 

- About Me

- My Friends

- My Thoughts

 

Each of these Tabs will be a subset of the entire "profile.php" and be in the center of the page.

 

Choices..

 

1.) I could just use a Query String ("profile.php?tab=aboutme") to load the different Tabs.

 

2.) I could get fancier and have a "profile" directory and a default "index.php" file *inside* that directory.

 

Then depending on the Tab selected, I could do something like this...

 

Pretty URL:

"profile/aboutme"

 

Ugly URL:

"profile/profile.php?tab=aboutme"

 

 

Here is what I used for my Articles...

RewriteRule articles/([a-zA-Z0-9_-]+)$ articles/article.php?slug=$1

 

There is also the issue of how I allow others to view a Member's Profile?!  (Right now I just have it so I look for the logged in Member's "memberID" and then show only their Profile.)

 

Advice welcome!

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

What about using

 

profile/DisplayName/showTab

 

You use the DisplayName just like the Article slug.

 

* If showTab is not provided, you default to the "AboutMe" tab

* If showTab is provided, but is invalid, you default to the "AboutMe" tab

* If DisplayName is not provided (and neither is the showTab) you default to the current user's "AboutMe" tab.

 

I'm not an expert with mod_rewrite, so I end up with a couple of rules to cover these. Pretty much the same as your Articles rule

 

RewriteRule profile/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1
RewriteRule profile/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1&tab=$2

 

The sequence of those two rules is important.

Make sure the character class includes everything that is valid for a user's Display Name.

Also, I usually include the optional trailing slash, just in case someone tries typing the URL manually and puts it on there.

 

This should cover:

  • profile/DavidAM
  • profile/DavidAM/
  • profile/DavidAM/AboutMe
  • profile/DavidAM/MyFriends (a very short list, indeed)
  • profile/DavidAM/MyFriends/

 

Link to comment
Share on other sites

Wow!  In depth answer!

 

What about using

 

profile/DisplayName/showTab

 

So "DisplayName" is more like <DisplayName> in that it can change, right?

 

What about "showTab"?  That can change too, right?

 

 

You use the DisplayName just like the Article slug.

 

* If showTab is not provided, you default to the "AboutMe" tab

* If showTab is provided, but is invalid, you default to the "AboutMe" tab

 

When I did my Articles, I have an "articles" directory with a default file of "index.php" however that file was a "Listing of Articles" and served as a landing page to which people could navigate to Articles.

 

In this case, my current "profile.php" file should be the landing page AND is also really the "About Me" page because I have the "About Me" tab displayed by default within the "profile.php" page if you follow?!

 

So what do I do?

 

I would think you always want an "index.php" file since by default Apache treats that as the default page if no file is specified in the "profile" directory.

 

I'm not sure if I could - or would want to - always have the URL read "profile/about-me" or not, although that is my inclination?!

 

 

* If DisplayName is not provided (and neither is the showTab) you default to the current user's "AboutMe" tab.

 

Sounds complicated?!  :-/

 

 

I'm not an expert with mod_rewrite, so I end up with a couple of rules to cover these. Pretty much the same as your Articles rule

 

RewriteRule profile/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1
RewriteRule profile/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1&tab=$2

 

Does

/?

mean "0 or 1 forward slashes"??

 

 

The sequence of those two rules is important.

Make sure the character class includes everything that is valid for a user's Display Name.

 

That could probably be another thread in itself?!  :o

 

Any thoughts on if I should *restrict* what a person can use for a Username?  (Right now I allow all characters from 8-30 in length.)

 

Maybe it would be easier to just say [a-zA-Z0-9] or is that too limiting?!  :shrug:

 

 

Also, I usually include the optional trailing slash, just in case someone tries typing the URL manually and puts it on there.

 

Okay.

 

 

This should cover:

  • profile/DavidAM
  • profile/DavidAM/
  • profile/DavidAM/AboutMe
  • profile/DavidAM/MyFriends (a very short list, indeed)
  • profile/DavidAM/MyFriends/

 

This all sounds good, but then I am a newbie!!!

 

Thanks,

 

 

Debbie

 

 

Link to comment
Share on other sites

So "DisplayName" is more like <DisplayName> in that it can change, right?

Right. Hopefully, each user has a "name" that can be displayed to other users; and this "DisplayName" is unique. Since it is unique, you can use it as a "Slug". So the URL would be different for each user.

 

What about "showTab"?  That can change too, right?

Yeah, it would be some string that your script can use to decide which tab to display

 

When I did my Articles, I have an "articles" directory with a default file of "index.php"

You could use an index.php file in a "profiles" subdirectory. It would (most likely) not present a list of users, though. You would check $_GET for the "user" and the "tab".

 

Sounds complicated?!

Not really ...

if (! isset($_GET['user'])) $user = $_SESSION['userDisplayName']; // Or however you are tracking the logged in user
else   $user = $_GET['user'];

$validTabs = array('AboutMe', 'MyFriends', 'MyThoughts');
if (! isset($_GET['tab'])) $tab = 'AboutMe';
else $tab = $_GET['tab'];
if (! in_array($tab, $validTabs)) $tab = 'AboutMe'; // Just in case they typed it wrong

 

I'm not sure if I could - or would want to - always have the URL read "profile/about-me"

I would. Then my page -- profile/DavidAM/about-me -- would be indexed in Google with my name right there (ain't that exciting!?)

 

Does

/?

mean "0 or 1 forward slashes"??

Yes

 

That could probably be another thread in itself?!

Actually, since you are using restrictive character classes, the sequence may not matter. I usually do it the lazy way:

RewriteRule profile/(.*)/?$ profile.php?user=$1
RewriteRule profile/(.*)/(.*)/?$ profile.php?user=$1&tab=$2

In which case, I have the rules backwards here. The second rule would never fire, because everything would match the first one.

 

Any thoughts on if I should *restrict* what a person can use for a Username?

If you are going to use it as a "Slug" then it needs to be restricted to valid URL characters. So you would need to exclude slash (/), colon ( : ), asterisk (*) and question mark (?) at the very least. I would allow at least: A-Za-z0-9 and some special characters. For mine, I allow space ( ), underscore (_) and dash (-). I DIS-allow

`~!@#$%^&*()+{}|:"<>?`=[]\\;',/

mostly because they would have to be urlencoded, and then it would not look as pretty; actually, it's more complicated. The path part of the url should be rawurlencoded, but the query strings should be urlencoded, so what happens when you move a path portion to a query string in mod_rewrite? Is the urldecoding handled properly? I wasn't sure, and so I just restricted everything that has to be encoded. --- I just noticed I have the backtick in there twice, now I have to go fix the script I copied that out of ...  :facepalm: dang, I did it in all three of my "bad characters" constants ... thanks for helping me find a "bug" in my code  :thumb-up: ... (a programmer's work is never done)

 

This all sounds good, but then I am a newbie!!!

You tend to ask very intelligent questions, and always seem to grasp the responses fairly well (yeah, I've noticed you around  ;D). It's really very close to the Articles code, just with the addition of a "tab" selection.

 

Did I miss anything?

Link to comment
Share on other sites

David,

 

Can I have a glass of milk with that, to wash things down?!  ;)

 

Very detailed descriptions so far, although no promises I'll be able to successfully implement it.

 

I'm a little shaky on the Regex stuff, and need to re-think what I want to allow for Usernames.  (Am thinking of being a meanie and restricting things to [a-zA-Z0-9_- ] but not sure...)

 

BTW, is what we are talking about conducive to not only a User being able to view their own Profile Tabs, but allowing the logged in User to view other Users' Profiles and Profile Tabs?  (I fear there is a whole bunch of stuff I am missing here as it is a big topic, and maybe that is even worthy of another thread?!)

 

Okay, past my bedtime, but I'll be back in the morning to try and start implementing some of this, since it sounds like you basically agree with the approach I was taking, just that you "added a cherry on top"!  *LOL*

 

Thanks!!

 

 

Debbie

 

 

Link to comment
Share on other sites

I'm a little shaky on the Regex stuff, and need to re-think what I want to allow for Usernames.  (Am thinking of being a meanie and restricting things to [a-zA-Z0-9_- ] but not sure...)

 

I think most sites limit to this, and not even allowing - and spaces. I think when it comes to usernames most people are accustomed to letters, numbers and underscore.

Link to comment
Share on other sites

Personally I don't see any reason to restrict your usernames so heavily. Sure I can see the point on systems like Linux where a space in a username would cause all kind of nightmares, but not for a PHP application where they will always be enclosed in quotes. Although I would always trim() the string first, to ensure the user doesn't register with a space by accident.

Link to comment
Share on other sites

I see your point, I'm just saying I think at this time, people are used to those restrictions. I can't recall the last time I saw someone's username with anything exotic like punctuation :)

 

If you want to allow other stuff, you can, I just can't imagine many people taking advantage of it unless you put a big disclaimer saying "YOU CAN USE AWESOME SYMBOLS HERE" ;)

 

Oh I forgot . I have seen several sites allow periods. I wish more would.

 

Another thing I'd add for the OP when you get to validating email address, don't exclude + or . in the part before @, those are allowed. I hate when a website tells me my email isn't valid when it is. But that takes me back to my rant about maiden names being longer than 3 characters.

Link to comment
Share on other sites

David,

 

What about using...

 

profile/DisplayName/showTab

 

This should cover:

  • profile/DavidAM
  • profile/DavidAM/
  • profile/DavidAM/AboutMe
  • profile/DavidAM/MyFriends (a very short list, indeed)
  • profile/DavidAM/MyFriends/

 

 

Well, I have been pining all day about how to not only structure my Member Profiles but also my entire website.

 

Right now I have all files related to a Member in a "members" directory which wasn't such a hot naming choice!

 

I am leaning towards creating a new directory in my Web Root called "account" and doing something like this...

http://local.debbie/account/upload.php
http://local.debbie/account/change_email.php
http://local.debbie/account/change_password.php
http://local.debbie/account/change_details.php
http://local.debbie/account/change_answers.php

 

What do you think about putting those files into an "account" directory?

 

 

Next is the question of "What do I do with the Member Profile?"

 

To me, a "Profile" is a SUB-component of the User's "Account", so I either want a "profile.php" file like I have or maybe even need a new sub-directory called "profile".

 

Is it redundant to have a "profile" directory inside of an "account" directory?!

 

 

The next issue is what to do with my "profile.php" file.  Because it has 3 Tabs in it, I either need 3 Files or one Template referencing 3 Query Strings.

 

I was leaning towards something like this...

http://local.debbie/account/profile/about-me
http://local.debbie/account/profile/my-thoughts
http://local.debbie/account/profile/my-friends

 

...where behind the scenes would be...

http://local.debbie/account/profile/index.php?tab=about-me
http://local.debbie/account/profile/index.php?tab=my-thoughts
http://local.debbie/account/profile/index.php?tab=my-friends

 

By creating a new "profile" sub-directory and having an "index.php" file, I would always have a default file displayed which could be like my Profile Page with 'About Me' tab showing.

 

What do you think about replacing my "profile.php" with an "index.php" file in a new "profile" sub-directory?

 

 

Finally, there is the issue of "How do I handle viewing other Members' Profiles??"

 

I currently store my Log In info in a SESSION variable, so I see no need to have "doubledee" in the URL since it is understood that I am looking at my own Profile!!

 

However, I did like your idea/format last night which used something like this...

http://local.debbie/account/profile/DavidAM/about-me
http://local.debbie/account/profile/DavidAM/my-thoughts
http://local.debbie/account/profile/DavidAM/my-friends

 

Were you planning on "DavidAM" just showing up when other people view your Profile, or would you see "DavidAM" if you were viewing your own Profile too?

 

I'm pretty unclear of what to do here...

 

Hope all of this makes sense?!

 

Thanks,

 

 

Debbie

 

 

Link to comment
Share on other sites

Debbie,

 

I really think you have a grasp on the possibilities, it's just that there are many different ways to do this, and most of them are perfectly valid, so you question whether you are doing it "right" or not. The most critical part of any programming project is design. It is also the most neglected. Think ahead about what you want to do with the profile, and where you will be placing links to it. Then consider what structure/format makes the most sense for most cases, and do it that way.

 

What do you think about putting those files into an "account" directory?

 

It sounds like a logical choice. Keep in mind, however, that if you are using mod_rewrite, the "directory" does not have to exist; and there does not even have to be a physical relationship between the URL "directory" and the web-root directory. This is advanced stuff, but you can rewrite a url, such as, http: //www.mydomain.com/account/userprofile/about-me/DavidAM so that it actually runs a script in <webroot>/profile.php with a query string of ?user=DavidAM&tab=about-me; or it could run a script in <webroot>/profile/index.php; or whatever.

 

Is it redundant to have a "profile" directory inside of an "account" directory?!

 

What do you think about replacing my "profile.php" with an "index.php" file in a new "profile" sub-directory?

 

I try to avoid creating a subdirectory that will have a single file in it. I would rather rewrite the request. With mod-rewrite, the user will (usually) not see the actual script filename so we could rewrite to lessImportantStuff.php if we want. I won't say it is wrong to do it, I just personally avoid it (mostly for maintenance reasons). But it really depends on your preference, and how the rest of your site is designed --- above all, be consistent, so you know where to look for the profile script if you need to modify it.

 

If you do create a directory, you are correct in suggesting that there be an index.php file in that directory. Otherwise, a request to the directory without parameters, could show the directory list, which leaks some information about your platform to potential blackhats (and isn't very user friendly, either).

 

Finally, there is the issue of "How do I handle viewing other Members' Profiles??"

 

We could swap the two parameters around, so the tab-name comes first in the url and the user-name comes last. We still have to handle the case where one or both are missing (show current user's about-me tab, or send the not-logged-in visitor to the registration page). Again, it is a matter of your preference. Since the rewrite rules will be sending the data as "named" parameters (i.e. $_GET['user']), it does not really matter what the url looks like. I would look at which "parameter" is most likely to be provided most often, and put it first -- in other words, look at which parameter is most likely to be omitted and put it last. Since on my my-friends page, I'm guessing you will list my friends as links to their profile, I figured the username will almost always be present and you would want the link to go to the about-me tab, so that could be omitted. On the other hand, you could be consistent and always provide both. I would recommend providing both on any "public" pages (pages that do not require a logged in user). Since these might be indexed by Google, you don't want to have two different links pointing to the same content. For the links to the current logged-in user's profile, this is not an issue, since Google is not going to have a login.

 

 

I hope I haven't confused you more than I've helped. It's been a long day and I'm not feeling very logical right now.

 

- David

Link to comment
Share on other sites

I really think you have a grasp on the possibilities, it's just that there are many different ways to do this, and most of them are perfectly valid, so you question whether you are doing it "right" or not. The most critical part of any programming project is design. It is also the most neglected. Think ahead about what you want to do with the profile, and where you will be placing links to it. Then consider what structure/format makes the most sense for most cases, and do it that way.

 

Glad to hear that at least one person thinks that I am on track?!  :shy:

 

 

I hope I haven't confused you more than I've helped. It's been a long day and I'm not feeling very logical right now.

 

- David

 

No, your posts in this thread have been VERY helpful so far.

 

I have a lot of "chewing" to do over the next several days.

 

I think I've got some of this figured out, but this is a pretty complicated module for someone who is still learning PHP!!

 

Will likely be back with more questions shortly, so don't go anywhere!

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

David,

 

Here is probably one of the trickier aspects of the Member Profile module...

 

How do I go about...

 

1.) Viewing My Own Profile?

 

2.) Viewing Other Members' Profiles?

 

 

For simplicity, let's forget about the Tabs, Pretty URL's, Directories, etc and say I have my base "profile.php"

 

Currently, I am logged in as "DoubleDee" and so I can see my entire Profile.  In fact, I can also edit it!

 

The URL I see is...

 

http://local.debbie/account/profile.php

 

...which works just fine if all I ever wanted to do was view my own Profile.

 

 

My current code in "profile.php" simply reads the "memberID" from the Member's $_SESSION and uses that to find and display the appropriate Member Profile.  HOWEVER, that won't work for the scenarios I describe below...

 

What would have to happen for "CowboyBob" to log in and view my Profile?

 

And what would need to happen for some Unregistered User to view my Profile?

 

Do I need two approaches and two scripts or can I do it all in one?!

 

I'm scratching my head on this one!  (The rest I can probably figure out pretty quickly.)

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

I believe DavidPM answered this question when posting this section of code.

$validTabs = array('AboutMe', 'MyFriends', 'MyThoughts');
if (! isset($_GET['tab'])) $tab = 'AboutMe';
else $tab = $_GET['tab'];
if (! in_array($tab, $validTabs)) $tab = 'AboutMe'; // Just in case they typed it wrong

if (! isset($_GET['user'])) $user = $_SESSION['userDisplayName']; // Or however you are tracking the logged in user
else   $user = $_GET['user'];

 

As you can see he's accounted for both $_GET['user'] and $_GET['tab'] here.  You then just do you RewriteRule for the page and show content based on the variables set here, assuming the the RewriteRule doesn't negate those GET values.  Hey I'm learning about this just now as well.  I believe I suggested you use the in_array() for validating the tabs as well when we talked about this.  At least that's a common suggestion.

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.