LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-06-2007, 07:52 PM   #1
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Rep: Reputation: 30
page name based on variables passed to it on PHP


Hello,
I have been searching on the internet to find a way to name a page based on variables passed to it without .php extentsion.

For instance, we have a website called www.website.com that has 4 users called user1,user2,user3 and user4. Each user has a special page on the website that can be found at www.website.com/username

I would be really glad if you let me know the name of such technique if there exist one so that I can find some tutorial about it.
 
Old 08-06-2007, 09:04 PM   #2
mattax.m
LQ Newbie
 
Registered: Aug 2007
Distribution: Kubuntu, Fedora
Posts: 8

Rep: Reputation: 0
Though I am unfamiliar with the PHP implementation, I have implemented a wiki using python (cherry py) that had dynamic pages like you have described.

cherry py maps a webpage to a python function and treats the ending url "stuff" as arguments to the function. In the scheme you described this would be set up as:

http://website.php?username=foo

this consequently (in cherry py) calls a python function with the argument username, based on the username you can do whatever you need to in order to render the page.

In my case, I stored page data in a mysql database and would simply make query based on the parameter, and then render the page by a template language (kid).

I am sure there is something similar to this in PHP, otherwise give a python solution a thought.
 
Old 08-06-2007, 09:31 PM   #3
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
I guess the easiest way to do this is to have a DNS server and map pages to a defined name. I think in yahoo, myspace and other sites they do the same thing.

For example, user1 can be mapped to www.website.com/users?username=user1, so that www.website.com/user1 shows content of www.website.com/users?username=user1.

But, I want to do it without DNS server.

I guess there should be a way to implement something like a DNS server using php.
 
Old 08-07-2007, 12:02 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
if username is a directory then it would just need to have a index.php file in that directory and apache will pick it up automatically. (So long as apache has been configured to do so and if you're using php then it should be)

Last edited by graemef; 08-07-2007 at 12:06 AM.
 
Old 08-08-2007, 09:25 PM   #5
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408

Original Poster
Rep: Reputation: 30
You are right. But it means that I have to make as many directories as number of users.
 
Old 08-08-2007, 09:50 PM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Yes but that can always be scripted for you, for example put it in a script that creates the users file, so instead of creating a single file called user1, you create a directory called user1 and in that directory you create a file called index.php. If (maybe later in time) the user can add an image to their "page" then that will be an extra resource and so it would be easier to keep it in a separate directory.

If you still don't like that idea then maybe you can look at apache server redirects, I'm not any good with them but I believe that you can configure apache to redirect the url to a certain resource.
 
Old 08-09-2007, 07:32 AM   #7
Jaqui
Member
 
Registered: Jan 2006
Location: Vancouver BC
Distribution: LFS, SLak, Gentoo, Debian
Posts: 291

Rep: Reputation: 36
Yup, you can configure apache to display specific content depending on what url is given.
but, unless all content is identicle, or it's a database powered site, you would need a different directory for each user.

apache has a very handy module for this, it's the mod_userdir.

this means each user gets a public_html folder in their home folder and apache will display the contents of that folder when given the url for it.

this is the old: http://example.com/~user/
[ note the ~ ]
 
Old 08-09-2007, 12:13 PM   #8
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Create a "controller" PHP script for your URL's. Make this basically take a $_GET param, like path, that holds the path requested by the user. So, write this page assuming this will be in the path. Then use apache rewrite to redirect all requests to that page, and stick the path on as a request parameter, like so, something like this (keep in mind I haven't written a redirect in a number of months):

Code:
RewriteRule ^([^?]*)?(.*)$ /controller.php?path=$1&$2 [R]
RewriteRule ^([^?]*)$ /controller.php?path=$1 [R]
With this rewrite, the contorller.php script will get a request paramter ($_GET key/value) path, and you can do your own logic now; like include some php page. If someone called www.yourdomain.com/username, then $_GET['path'] == 'username'

When creating a site, I like creating a "Controller" class. This class basically takes the list of modified $_GET key/values, and the path relative to the other controllers. The class also has some function that decides whether or not it can handle a given path. Each Controller can hold more Controllers. And each Controller may take off parts of the path, so the path may not be the original. Whenever a request come in, it basically goes through a hierarchy of Controllers, until it finds the final one that handles the actual path. Then I usually create an abstract class called "Action" that can be registered with a controller and is similar to a controller, except that multiple Actions can be registered for one path.

Last edited by 95se; 08-09-2007 at 12:17 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: session variables not being passed properly Robhogg Programming 4 07-28-2007 07:38 PM
awk: /matching/ variables passed with -v aunquarra Linux - General 2 02-17-2005 06:47 PM
What are the names of the variables passed to konqueror's email client? BluePyre Linux - Software 0 07-04-2004 11:33 AM
PHP, passing a lot of variables to another page Robert0380 Programming 4 09-07-2003 04:44 AM
php variables not being passed on tpat Linux - Software 1 01-11-2003 03:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration