Go Back   Dynamic Drive Forums > General Coding > PHP
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-19-2006, 04:28 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 Posts
Default URLS like: index.php?page=page1 ???

I have links on my page, but instead of linking to pages like:
Code:
<a href="guestbook.php">Guestbook</a>
I would like to have

Code:
<a href="?page=1">Guestbook</a>
How can I do this?
Reply With Quote
  #2  
Old 10-19-2006, 04:59 PM
mwinter mwinter is offline
Elite Coders
 
Join Date: Dec 2004
Location: UK
Posts: 2,361
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mburt
... instead of linking to pages like:
Code:
<a href="guestbook.php">Guestbook</a>
I would like to have

Code:
<a href="?page=1">Guestbook</a>
How can I do this?
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.

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
Reply With Quote
  #3  
Old 10-19-2006, 05:00 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 Posts
Default

It leaves off the extension, possibly making it easier to navigate.
Reply With Quote
  #4  
Old 10-19-2006, 05:03 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 Posts
Default

So how could I do this?
Reply With Quote
  #5  
Old 10-19-2006, 05:19 PM
mwinter mwinter is offline
Elite Coders
 
Join Date: Dec 2004
Location: UK
Posts: 2,361
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6  
Old 10-19-2006, 05:23 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 Posts
Default

I've read that post, I couldn't understand it.
Code:
So then why don't you aim for URIs like:

  http://www.example.com/guestbook
I would... but I don't know how. What's a URI?
Reply With Quote
  #7  
Old 10-19-2006, 08:05 PM
costas costas is offline
Junior Coders
 
Join Date: Aug 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Code:
<?
$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>
members.php
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!";
?>
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!!

Hope I helped!!!
Reply With Quote
  #8  
Old 10-19-2006, 08:15 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

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!
Reply With Quote
  #9  
Old 10-19-2006, 10:22 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 Posts
Default

Okay.. I think I get it now. Thanks Mwinter, Twey, and costas. PHP is awesome...
Reply With Quote
  #10  
Old 10-19-2006, 10:49 PM
djr33's Avatar
djr33 djr33 is offline
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 Posts
Default

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.
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. 
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.

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 - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:27 AM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.