Forum Moderators: coopster

Message Too Old, No Replies

PHP Sessions/Privacy, Individual User Pages?

         

AshenSeraphim

3:51 am on Mar 7, 2009 (gmt 0)

10+ Year Member



Hi all!
Long time reader, first time poster.
I'm working on a personal website for myself, basically trying to pull all my collective talents together under one roof in attempt to make it a bit easier to generate a little extra income in these unstable times.

Anyway, the current issue I'm having is figuring out exactly how to get individual private user pages for my clients.
I'd like to be able to let them register an account (Or I can manually create the account if it'd make any difference, doesn't matter to me) and upon logging in I'd like them to be re-directed to a private page all of their own that I can keep an updated list of project files on, etc, as well as have an upload form for them to easily kick source materials and whathaveyou to me.
I've got the basic user login/registration/etc scripts up and running, I've had several friends as well as myself make test accounts and the DB and Scripts all work perfectly. I just need to know what to add in to get the private client pages up and running.

Thanks in advance for your help!

IanKelley

5:04 am on Mar 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure I understand the problem... If you have the login/validation finished then just have the private page check to make sure the user is logged in (either via a cookie or session) and if not send them to the login page.

AshenSeraphim

5:23 am on Mar 7, 2009 (gmt 0)

10+ Year Member



What you just described is exactly what I have running right now.

What I'm looking to do is have individualized pages. As of right now everyone who logs in goes to the same private page, I want to have each user account redirected to its own page that no one else can access.
Is that possible?

IanKelley

5:42 am on Mar 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Send them to the same page/script but serve different content depending on which user it is.

It's essentially the same thing.

AshenSeraphim

6:39 am on Mar 7, 2009 (gmt 0)

10+ Year Member



That's what I'm not sure of how to do, I'm still fairly new to PHP so I'm not quite sure how to route each user to a specific page depending on their DB ID, or whatever kind of identifier one would use.
Is there any way I could get an example, or a link to a tutorial perhaps? I hate to ask for spoon-feeding but I'm pressed for time on this and would like to get it going as quickly as possible.

IanKelley

7:51 am on Mar 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure exactly what you want on the individual user pages, but here's one scenario:

private.php is a script that users access after logging into the member's area.

Each user has saved certain data to their private area which you have stored in a MySQL database. Or perhaps you have saved the data for them.

In any case, once private.php has determined that it has a valid user, it would then perform a database query using the user's ID or username. The query would return the user's saved data which private.php would then display for them.

If this is what you want to do, I did a quick search and found this:

[tutorialized.com...]

I didn't look over the tutorial so I can't say how good it is but there should be a section that goes over building a customized member's area page for each user, which is what you want.

The other areas of the tutorial might give you some tips for your login system as well.

Hope that helps. If not, you should be able to Google other tutorials.

AshenSeraphim

11:28 am on Mar 7, 2009 (gmt 0)

10+ Year Member



Well, I got it working!
The tutorialized link above didn't have anything about individual user pages, so I snooped around some more and ran across this;
[phpfreaks.com...]

all I had to do was change my headers around and wha-lah!

The only problem I have now is restricting access to the pages... like I said I'm new at this, so configuring cookies and whatnot is way out of my knowledge base.

If anyone has any suggestions about securing pages and only allowing access to a certain username or something like that I'd appreciate the help.
If not, I'll figure it out eventually. =]
Right now I'm gonna hit the hay and start fresh tomorrow.

Thanks for your help so far, Ian!

AshenSeraphim

10:57 pm on Mar 7, 2009 (gmt 0)

10+ Year Member



Well.. I've been looking around for the past few hours here and I haven't been able to find anything close to what I'm looking for.

From what I can see I have two options. I can either use a cookie or a session.. but regardless of which one I end up using, how can I set a certain page to only allow a specific user on it? I've tried fiddling with cookies to see if I could redirect users that didn't have the required name for the page, but I've yet to have any success. Help? =/

IanKelley

11:26 pm on Mar 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need a different page for each member... You just need one script that serves different content for each user that accesses it.

Try to get your head around the above as it is the fundamental principle behind the use of back end scripting on the web :-)

The private.php (or whatever) page would work basically like this:

if (checklogin()) {
$content = readDataFor($userID);
print $myheader;
print $content;
print $myfooter;
}
else { //redirect user to login script
}

checklogin() verifies that the cookied or session login data is valid.
readDataFor() queries the database to get the stored custom data for the user accessing the page.

AshenSeraphim

11:39 pm on Mar 7, 2009 (gmt 0)

10+ Year Member



So, if I've got this right, I'd be storing each users data in a DB, and then serving it to the private.php page based on their userID?

How exactly do I get their data in there? Would I be creating a table and filling it with the data, or..?

Jeez, I'm so sorry for being such a pain, this is my first experience with DB's :(

IanKelley

12:10 am on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was assuming that you had already learned about DBs when you created your login system... If not you might want to look into a basic MySQL tutorial.

Yes you would create a table for the content, with the primary key (column) being the username or user ID. How many other columns you use, and the types of columns, will depend on what you're storing.

AshenSeraphim

12:34 am on Mar 8, 2009 (gmt 0)

10+ Year Member



Yeah, I know enough to make a few tables and get everything connected.. but like I said before I'm in a bit of a rush so I haven't been properly studying everything as I should be.

I'll look into how to set that all up, I assume that it'll be pretty basic, all I need to do is give them an upload form and a list of project related documents/materials to download from my server.

Is something like this very easily maintained or am I barking up the wrong tree for a client project management type system here?
For all I know I could be doing this in the hardest way possible, haha. :)

IanKelley

12:47 am on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're definitely headed in correct general direction :-)

Images and other binary files can be stored in the database but might also be stored in user specific directories in the file system.

In either case you'll still want to store the overview data (user ID, filename, etc...) in the database as that is where you'll be cross referencing to the user's login details.

AshenSeraphim

1:16 am on Mar 8, 2009 (gmt 0)

10+ Year Member



Excellent :D

What would be the most efficient/easy way to do it? Storing the files/images in a DB, or in a user specific directory? I don't want to tax the system too much (not that I'm going to be having thousands of users or anything, but still).
I'm thinking perhaps a user specific directory would be a better choice, as I could FTP in and upload materials easily as well as have it serve as a landing spot for their uploaded files via the upload form that I'll most likely be doing using jquery or something similar.

I'll be searching around on my own for tutorials or tips on how to get this all running but in the meantime do you have any extra tips/examples/tutorials handy?

Thanks again for you help, hopefully I'll have this fully functional within the next few days :D

IanKelley

1:32 am on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Using the file system would require less coding and would not be more resource intensive (since MySQL generally can't use caching for very large files like images, especially when they are not frequently accessed) so probably that's the way to go.

If the point of the system is just to allow the transfer of files between you and your clients then you really wouldn't need to use the database at all (outside of the registration and login system), just generate a linked list of files in their directory for them. The directory name itself (their user ID) is enough to link their login to their files.

AshenSeraphim

1:45 am on Mar 8, 2009 (gmt 0)

10+ Year Member



Sounds good, I can stick pretty close to what I've already got set up then.
One final(ish) question though, how exactly do I link a userid to specific files/folders?
And if I do link the id to the files, that will lock out all other users from accessing those files, correct?

Ah, and about that example code you gave me a few posts up, where exactly do I need to pull the content from?
I'm still confused as to how exactly to get individual data on that same page.
I'm guessing at the moment that I need to add some data into the DB and have content (e.g., list of links to the files in their directory, etc) in there.. Or can I link their userid to a php page inside their directory and have it show that, perhaps?
I'm probably way of, I'm sorry.. if I wasn't in such a crunch for time I'd probably be able to get this figured out on my own without having to bug you for your help. Thank you again though. :)

IanKelley

2:23 am on Mar 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The user ID would be linked because their directory would be named with their user ID.

However in theory, because of the way PHP's permissions work (PHP generally needs a directory to have public permissions in order to access the files it contains) it would be possible for someone to access a user's files by navigating directly to the directory with their browser.

There are various ways to avoid this but that's kind of a broad topic. It's probably not something you need to worry too much about as it's unlikely that anyone is going to know another user's ID.