Jump to content

Archived

This topic is now archived and is closed to further replies.

mrbrightside

Php variable passing help

Recommended Posts

Im currently building a site for a university project, and im stuck with something.

basically I have a users page were you can view a users profile. I pass the username to the page and the users details are loaded.

for example.

http://www.mywebsite.com/users/index.php?username=mrbrightside

so that all works. But I want to be a bit more professional with this and somehow hide the variable name. Ive seen it done on other website, but cant work out how or if it is possible to do using PHP. Basically how i want the URL to appear would be:

http://www.mywebsite.com/users/mrbrightside

so the user name is passed, but you dont see the name of the page (index.php) nor the query string (?username=mrbrightside)

is this possible? - if so how?

thanks a million in advance

stuart

Share this post


Link to post
Share on other sites
That is done in Apache, with mod_rewrite. You can't do it with php.

Share this post


Link to post
Share on other sites
Really.  ;D

If your host supports it you could look into mod_rewrite. Drop them an email and read [url=http://www.workingwith.me.uk/articles/scripting/mod_rewrite]this[/url].

Share this post


Link to post
Share on other sites
ok well thanks for answering to my post so quickly anyway!

I have played with .htaccess files before on another website i build, but this current one is hosted with godaddy.com, and I got a horrible feeling they dont allow you to mess with that kind of stuff.

I will investigate anyway - thanks

Share this post


Link to post
Share on other sites
Two other options for you mrbrightside,

One, code all your variables in form elements and use $_POST['xyz'] to get them.

Two, use sessions to hold your variables and use $_SESSION['xyz'] to get them.

For either one, you'd want some sort of interface where you could set the variable, then store it by your chosen method, and display or whatever.

Two can be tricky if you're unfamiliar with session variables.

Jeff

Share this post


Link to post
Share on other sites
thanks for your suggestions
im not too bad with sessions but dont really want too many of them flying about to hold variables like this. Im looking into the mod_rewrite solution as it seems exactly what I need to do, I just hope I can get it to work with godaddy.com

Share this post


Link to post
Share on other sites
THANKYOU 448191

A quick read through the link you suggested and a few attempts later and I got it all working!

godaddy does support mod_rewrites!

It didnt work when I tested if through the full subdomain path:

e.g.

http://beta.myurl.com/users/mrbrightside

but did work through the full url:

http://www.myurl.com/beta/users/mrbrightside

maybe im doing something wrong in the .htaccess file, but at least it works!

thanks again

stuart

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.