views:

120

answers:

3

Hey guys - im using var passing links like this to jump around a site...

<a href = "index.php?content=about.html">

...problem is, i have all the ugly var info visible in the url. I would usually hide it by using the post method, but i dont have any form tags, so is it even possible?

Thanks!!!!!!!

+5  A: 

It's a bad idea. GET is used for reading, POST is used for updating. A better solution would be to use some sort of mod_rewrite to make friendly URLS. Often called SEO friendly URLS...

Yes, you can POST with a <a href... but you have to have a lot of ugly javascript to do it... which breaks all sort of standard conventions.

Update, combining some new information

@FDisk has the simplest solution below, but I would add a condition to it which would allow existing files to be passed through directly by the webserver without having to run it through PHP:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /index.php?content=$1 [L]

That way, a request to /images/bar.png will be served directly from the filesystem if that image exists.

Note, that your page does not necessarily need to have ".html" on the end anymore. So your URL could look like: http://example.com/about which would then be converted to: index.php?content=about

Taking it one step further from the link you listed in your post, you could then parse the url for various parameter. The example you looked up stuffed them into [$_GET, $HTTP_GET_VARS, $_REQUEST] respectively, but I think that's not such a good idea. Just make your own array of parameters.

DGM
thx for the info! i found this code for a simple mod_rewrite func. Does this look like the right direction for what i need? www.roscripts.com/Mod_rewrite_and_PHP_functions-47.html
realcheesypizza
That page has one possible way of doing things... but I would leave out the "register_globals" part, it's dangerous.
DGM
yes - you are right
FDisk
A: 

you can hide info (var name and content) by encoding it. Thus the user won't be able to understand or change what you are passing around. But he will still see something in his url.

I guess you should give use some more context to understand why you cant use direct links to static pages ?

kriss
So ya i just like having a single index page with includes for the nav, header and footer. It saves a lot of repetitive code and seems to load super fast. Only drawback i guess is the ugly urls. Its not a high traffic site by any means so i'll prolly just let it slide, unless ur encoding or the mod_rewrite works.any other info on the url encoding so i can research?
realcheesypizza
+2  A: 

You can try using the mod_rewrite extention

The original URL:

http://www.youwebsite.com/index.php?content=about.html

The rewritten URL:

http://www.youwebsite.com/about.html


.haccess file content:

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?content=$1 [L]
FDisk
The one problem there is that you also are passing all image and asset urls in to the script. A condition should be placed before that to skip the script if a file by that name already exists.
DGM
Even worse: `index.php` would also match.
Gumbo