Forum Moderators: coopster

Message Too Old, No Replies

Passing variables with $PATH_INFO

         

carbonspace

7:57 pm on Nov 21, 2003 (gmt 0)

10+ Year Member



I've managed to create flat html files using PHP's explode function but can't seem to recover the variables that were originally being passed thru the URL with the $_GET function in a previous iteration.

Here's my old code:

$state =!empty($_GET['state'])? $state = $_GET['state'] : $state = '';

if (isset ($_GET[state]))
{
$stateName = $_GET[state];
}
and my links looked like this:

<a href="<?=$_SERVER['PHP_SELF']?>?state=Colorado">Colorado</a><br>

ok. Using this code I would obviously get urls like this:

[site.com...]

and I could place this <?=$stateName?> wherever I want and it would return whatever state the user clicked on.

Now I'm using this bit of code to explode the url and separate it into individual variables:

list($first, $id) = explode('/', $PATH_INFO);

and I changed my links to this

<a href="<?=$_SERVER['PHP_SELF']?>/Alaska">Alaska</a><br>

in an effort to get urls similiar to:

www.site.com/page.html/Alaska

This part seems the become irrelevant since there is no [state]:
$state =!empty($_GET['state'])? $state = $_GET['state'] : $state = '';

if (isset ($_GET[state]))
{
$stateName = $_GET[state];
}

1.The variable orginally passed thru using $_GET is lost since I changed "?state=" to a "/".
2.I also want to have the resulting url be:
www.site.com/Alaska.html <---

Can anyone offer some insight on how to get my variables back and accomplish my 2 goals? I've heard theres a mod_rewrite rule that can be applied to display a clean url in the address bar but I don't see how that's possible without changing my code and links. I've already written rewrite rules so a url (www.site.com/page.html/Colorado) typed into the browser is returned as www.site.com/page.html?state=Colorado. That works just fine, I just need to do this in reverse so I don't have to use mod_rewrite and the url is simply displayed as flatly as possible. I just need a push in the right direction if anyone is willing...

Thanks in advance for all your help and please ask if I didn't make myslef clear on any of this.

-dm

carbonspace

6:14 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



I must be way off...

jatar_k

2:05 am on Nov 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry carbonspace,

Was this thread not quite the answer?
[webmasterworld.com...]

carbonspace

4:37 am on Nov 25, 2003 (gmt 0)

10+ Year Member



No sweat, thanks for responding, j

The URL rewriting is working perfectly, but this is a bit different. The best way to put it is I'd like for my URL to appear flat from the start but still incorporate the dynamic content I'm using with my $_GET variable. I'd like to make my URL's clean without mod_rewrite and search friendly from the beginning. I just have to learn how to use the variables that are created when I use the explode function.

list($dummy, $state) = explode('/', $PATH_INFO);

If there's a better way you or anyone can suggest to keep the actual URL as close to the root as possible (www.abc.com/abcd.html)but still have a navigation system like you'd get with www.abc.com/foo.php?id=abcd, I'd like to hear it.

I'm sure I'll find what I need sooner or later. I'm seaching this site like crazy as well as others and have always found the info I'm looking for.

"..onward, thru the fog!"

carbonspace

9:33 pm on Nov 25, 2003 (gmt 0)

10+ Year Member



Once I had a cup of coffee, it all became clear....

<?=$state?>