I am currently working on a social networking website, and I would like the user to be able to enter the web address of another user and be redirected to his profile. The thing is, every existing user has a column in a mySQL DataBase, which specifies what page templates does he use, and the data to be inputted into this template. How can i Possibly make it so that when he inputs of example : http://www.emuze.co/users/@bob_marly (it can have a .PHP/ .HTML suffix after it), the website will query the Database, find the template, redirect to that templates page (eg http://www.emuze.co/temps/temp1.0.php ) and use the users that a from the mySQL Database? I know its a very long and complicated question, but i would really appreciate any help! thanks a lot! :@
If I understood your question right, you mean this:
So user A wants to see the site from user B. User A has template T_A, user B has template T_B. User A goes to www.emuze.co/users/B and watches it using template T_A.
If this is right, do it like this: Read out the data from user B from the database. Load the watchings user profile, check wich template he is using and then render the site using the template (in this cast T_A) and the data of the user (B).
Very easy example:
user database:
|Name | Information | Template
_______________________________________
|A |I'm user A | T_A
|B |I'm user B | T_B
Templates: T_A:
"Hey, I am %NAME%, Some Infos about me: %INFORMATION%"
T_B:
"Name: $NAME", Information: %INFORMATION"
User A wants to look at User B:
Get user B's values from db
Get user A's Template
replace `%NAME%` and `%INFORMATION%`
print it
UPDATE:
I think what you need is some mod_rewrite (under Apache, under IIS use rewrite rules), wich maps http://example.com/users/bob_marley to http://example.com/users/index.php?user=bob_marley . Using this you always get to that site and can do anything there.
You should not use a real existing file per user, but one wich gets params like this. And you should use a template system, so you can echo a templete everywhere without redirecting users.
You should give each user a row instead of a column, within a table that specifies which template is used for each user.
For example, you would have the "templates"-table, with the columns "UserID", "Username" and "Template". Then, the table would look something like this:
+--------+----------+----------+
| UserID | Username | Template |
+--------+----------+----------+
| 1 | John | temp1.0 |
| 2 | Paul | temp1.1 |
| 3 | Eric | temp1.0 |
| 4 | Frank | temp1.2 |
+--------+----------+----------+
...and soforth.
Then you'd have to query which template a user has. For example, to know which template the user with UserID '3' uses, assuming your mysql connection resource is stored in the variable $link:
$query = "SELECT * FROM templates WHERE UserID=3";
$result = $link->query($query);
$row = $result->fetch_assoc();
$row['Template'] will result 'temp1.0' which you could use for including a specific CSS-stylesheet, including specific PHP-files or whatever, but you can also retrieve all other user-specific information such as $row['Username']. No need for redirections.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.