Jump to content


Photo

Php variable passing help


  • Please log in to reply
8 replies to this topic

#1 mrbrightside

mrbrightside
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 September 2006 - 08:31 PM

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...me=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...rs/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

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 08 September 2006 - 08:46 PM

Edit: ...after reading your question a second time.

PHP Ninja

#3 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 08 September 2006 - 08:49 PM

That is done in Apache, with mod_rewrite. You can't do it with php.

#4 mrbrightside

mrbrightside
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 September 2006 - 08:55 PM

really? no way at all?

darn! - oh well thanks anyway :'(



#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 08 September 2006 - 09:19 PM

Really.  ;D

If your host supports it you could look into mod_rewrite. Drop them an email and read this.

#6 mrbrightside

mrbrightside
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 September 2006 - 09:46 PM

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

#7 jefkin

jefkin
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 08 September 2006 - 09:55 PM

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

#8 mrbrightside

mrbrightside
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 September 2006 - 10:04 PM

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

#9 mrbrightside

mrbrightside
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 September 2006 - 10:24 PM

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.co...rs/mrbrightside

but did work through the full url:

http://www.myurl.com...rs/mrbrightside

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

thanks again

stuart




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users