ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Rep:
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.
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:
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.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Original Poster
Rep:
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.
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)
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.
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.
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):
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.