Re: Newbie Question: How to pass URL info to .php script ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 19, 2008 at 1:18 AM, Ethan Whitt <ethan.j.whitt@xxxxxxxxx>
wrote:

> I pasted your example in and it doesn't work for me (again, newbie).  I
> will play with it and see if I can get it working.  My main goal is to have
> Ruby-like URL's vs "?var=3425".  Is this possible with .php (without
> mod_rewrite / something in the http server?)


i just typed it into the browser so it could have some mistakes.  well to
answer your question, yes, you can use external redirects from php, and if
you store the query string (part of url past ?) then it can be made
accessible to whatever file youve redirected the client to.  so like, a
client request a page, say,

http://youresite.com/somedir?a=5&b=6

in somedir, on your webserver, you just put an index.php file.  then in
there, you do something like put the values $_GET['a'] and $_GET['b'] in
some persistent storage, like $_SESSION, a db, or just in a file somewhere.
then you use header to redirect the client to a url that doenst have the
query string, something like

if(!empty($_GET)) {
  /// store $_GET vars
  header('Location: http://yoursite.com/somedir');
} else {
  /// check storage location for vars to load
  /// make sure to filter said vars !
}

while this approach is effective, i consider it messy / inefficient /
cumbersome, and personally favor mod_rewrite.  if you look into code igniter
or other frameworks, you can see how they are managing the implementation of
pretty urls.  most of them will favor mod_rewrite, but offer an alternative
for people who dont want to use it or dont have access to it (because of
hosting provider for example).  so you might dig into some open source code
for a nice tested solution to your problem.

and digging through open source code can just be so much fun ;D

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux