I’m sure this question has been asked before but I have used the search feature and cannot find an answer. Maybe because i’m not quite sure what I should be looking for so please bear with me.
Basically, I have set up a simple user login/registration system, which gives users access to index.php, where it displays their own account data when they are logged in. So this page allows them to update their profile and upload images etc.
But now, I want each user to have a publicly viewable profile where this data is displayed on a directory such as http:www.mysite.com/user/username/index.php. And now i’m unsure how to do this. The main thing I am struggling with is how this can be done dynamically when the user registers.
I would guess your problem is that your actually using directories to create URL structure. Normally, you would using the mod_rewrite module of Apache to ‘imply’ that there is a directory there, but in fact here isn’t.
Ok so mod_rewrite can help give me nice looking static URLs? but i’m still a bit confused about how the dynamic URL is created when a user registers? or am I missing your point?
I’m trying to understand. I think my code is quite different and i’m not sure how what you are showing me would integrate with the way I am currently doing things? Am I doing it wrong?
If you want to create the urls you stated in your original post, you either have to use mod_rewrite or upon registration, have your script actually create that physical directory structure, which isn’t advisable.
If you are willing to change your url, you could have a separate script to display the user profile to unauthenticated visitors however.
view-user.php?username=anthony
You’re going to need to decide on how you wish to proceed I’m afraid.
So what he was trying to tell you is to enable the mod_rewrite module of apache . You may want to uncomment it , depending upon the OS ( Googling will get a lot of solutions for the OS you are using ).
You may want to create a .htaccess file in the public folder .
The module=user is a user.php page which may be stored in the module folder or something . You can copy the contents from your file that are needed to printed to user.php after he logs in.
The index.php will be the one which prints the contents of the module files . You should change your index.php file which is shown now to something like
include_once('header.php');
// somefunction that fetch the module and prints . Need to confirm whether the module exists , permissions etc here .
include_once('footer.php');
I think you may need to look more inorder to know how it works . These techniques are very much useful in security also. You may need to look more …