I have links on my page, but instead of linking to pages like:
I would like to haveCode:<a href="guestbook.php">Guestbook</a>
How can I do this?Code:<a href="?page=1">Guestbook</a>
I have links on my page, but instead of linking to pages like:
I would like to haveCode:<a href="guestbook.php">Guestbook</a>
How can I do this?Code:<a href="?page=1">Guestbook</a>
- Mike
Uh, why would you want to do that? URLs should be transcribable and easy to remember. Ideally, the query string should be used only to modify details about a particular document, not choose the document itself.Originally Posted by mburt
Jakob Nielsen has a few guidelines regarding URIs and their importance as a UI feature, sentiments that are echoed elsewhere.
What exactly makes you think this will be a good idea, either for visitors or yourself?
Mike
It leaves off the extension, possibly making it easier to navigate.
- Mike
So how could I do this?
- Mike
So then why don't you aim for URIs like:
  http://www.example.com/guestbook
Still no "extension", but no unnecessary query string silliness.
I've discussed how to implement extension-less URIs in the past - you even participated in one thread.
Mike
I've read that post, I couldn't understand it.
I would... but I don't know how. What's a URI?Code:So then why don't you aim for URIs like: http://www.example.com/guestbook
- Mike
If I understood well, you want to use links that have that "?" in the end, like "<a href="login.php?user=username">Login</a>". Well, here's an example:
index.html
members.phpCode:<? $user = $_POST[user]; if(user != NULL) { header("Location: members.php?user=$user"); } ?> .... <body> <form action="<? echo $_SERVER['PHP_SELF'];?>" method="post"> Username: <input type="text" name="user"> <br><br><input type="submit" value="Login"> </form> </body>
This is a very simple example, but I hope you understand how it works. If you want a bit bigger and more complex example, I could give you one I've made!!Code:<? $user = $_GET[user]; // you MUST use the "get" method if($user == "costas") // then verify it echo "Welcome oh COSTAS!!"; else echo "You are an unauthorized User!"; ?>
Hope I helped!!!
The easiest way to do this is to construct a query-string mechanism as you describe here, then use mod_rewrite or equivalent to map /guestbook to /?page=1.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Okay.. I think I get it now. Thanks Mwinter, Twey, and costas. PHP is awesome...
- Mike
You could, if you're just looking for a nice feel to the url, use page.php?guestbook
Then split the string of the url to work.This isn't necessarily a great idea, but it might help. If you want simplicity and a single php page as the basis for navigation, could work well.PHP Code:list($addr,$page) = explode($_SERVER['REQUEST_URI'],"?",2);
//set the two variables equal to the parts of: URI split at ?, limited to 2 chunks.
echo $page;
//that's "guestbook", etc.
Note, though, that a major problem is that you can't use GET variables after this. If you wanted to specify something else with the URI, then the & would have to be there, and it would get messy, as that would be in the $page string as well.
You could do some fancy coding, but it would just be a pain.
In that case, you should definitely use ?page=.... instead. It would also make it clearer when making the URLs.
One ?.... value is easy, but after that, using the normal syntax is much clearer.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks