Forum Moderators: coopster

Message Too Old, No Replies

What is the correct method of posting url variables?

         

anzagi

3:29 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



I have a text link,
<a href="apage.php?subject=variable1&amppage=variable">link</a>

both variables are hard coded into the link, the first being a product name and the second being the url the user is on so it would look like this

<a href="apage.php?subject=product&amppage=index.php">link</a>

However, I am getting a 406 error, now it works with just using the first variable so it must be something i am doing wrong with the second one. Is that the correct way to insert 2 url variables in 1 string?

Many thanks

jatar_k

3:35 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld anzagi,

maybe the dot, try using the pagename without the extension, like so

<a href="apage.php?subject=product&amppage=index">link</a>

anzagi

3:48 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



nope....
my
my variable string looks like this:
../forms/index.php?subject=product&amp;page=../folder1/folder2/folder3/index.php

../ (taking you back upto level 1)

and the error I get is

406 Not Acceptable

An appropriate representation of the requested resource level1/forms/index.php could not be found on this server.

anzagi

3:56 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



If I remove the second variable, so just have subject=product it works fine....only when I add the second variable do I get the error. its also worth noting it works fine with both variables locally, but not on my live web server.

Murdoch

3:57 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



<a href="apage.php?subject=variable1&amppage=variable">link</a>

You're not trying to pass the ampersand as the HTML special entity &amp; are you?

Shouldn't your query string actually be

apage.php?subject=variable&page=variable

You'll definitely get an error especially if you are trying to pass certain non-alphanumeric symbols.

anzagi

4:01 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



well I wasn't sure, I know it needs a & to seperate the two variables but wasn't sure if it should be & or amp; anyhow I changed back to & now and I still get the same error :(

barns101

4:05 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



Could you use urlencode() to correctly encode your URL?

Murdoch

6:07 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



I'm a little confused on what you are trying to do. Are you attempting to access /folder1/folder2/folder3/index.php via a variable? I doubt this will work.

Why aren't you just putting the link like "yourdomain.com/folder1/folder2/folder3/index.php?product=variable? What is in that section of your website that you need to pull other than the page itself?

Are you sure you wouldn't just rather use an include statement instead of trying to pass it through the query string?

There's always a way to use mod rewrite to do most things (you should be using it anyway with dynamic URLs) so once I have an idea of what you want to achieve we can tackle it from there.

If you want to go into specifics about your site you can sticky mail me with the address.

Thanks
-Doc

PHP_Chimp

6:10 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although this wont sort your problem it may point you in the correct direction.

Check what you are getting the the $_GET array.


echo '<pre>';
print_r($_GET);
echo '</pre>';

Then you may be able to see what is 'unacceptable' about your get array.

As it is working on one server but not on another have a look in your htaccess. As you may find that something is rewriting your rule, so what you want is getting mangled.

Also check that you are using the same version of your code on both servers.

jatar_k

6:16 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it's just your format

page=../folder1/folder2/folder3/index.php

that isn't acceptable as a value, you can't have the / or . in there, apache is tying to resolve the path and it's not write so it chokes and sends you a 406

[en.wikipedia.org...]

PHP_Chimp

6:22 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Durrr...Should have spotted that.
Try running your links through urlencode [uk.php.net], as that will save you changing them by hand.
There is a load of information in the manual so have a read, as there are a few ways you could encode your url's.

anzagi

8:13 am on Apr 14, 2008 (gmt 0)

10+ Year Member



Hi, thanks for all of the replies. What I am trying to acheieve (i'm new to php incase you hadn't guessed!), is this: Say I am on index.php, I would like to pass that file name to my form confirmation page, which then uses a redirect to send the user ack to where they were (i.e. index.php). And it knows this by referencing the vaiable that has been passed in the url....does that make sense?

Murdoch

1:13 pm on Apr 14, 2008 (gmt 0)

10+ Year Member



I get what you're saying. As far as I know (and BTW I am no expert either) there are two ways that this can be achieved.

The first is to use $HTTP_REFERER, which captures the referring page. Then you could populate the redirect (PHP or Javascript) with that information. However, $HTTP_REFERER isn't always on point, as browsers can sometimes block the referrer information depending on settings. However this is the easiest way.

I (personally) would think the best thing to do is to either:

A. Set up some kind of variable mapping to your pages (as a separate PHP file) and include that file into your pages OR

B. Set up a mod rewrite that will allow you to pass the page names as "variable-friendly" and then populate the links with those versions of the URLs.

I think if you are serious about SEO and your site you should set up a mod rewrite for your dynamic URLs so that they look static anyway. This is basic SEO 101 stuff and if you are early into the creation of your site this is recommended.

jatar_k

1:14 pm on Apr 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my main question is why?

the logic of what you are doing I understand but my best answer depends on a lot more things.

you could use a cookie
you could use a session variable
you could store all of your pages/urls in a database and assign them all an id and only pass this id
you could find ways to pass only a unique part of the path and then always append index.php and send them there

there are a lot of ways to do it but you have to stay away from putting those special characters in the url

if you do sessions or cookies then you need to worry about your site still being accessible by SE spiders or what happens if the user doesn't accept cookies

if you don't already have a database then the db method could slow down the site and make a lot of work for nothing

again, we come back to the why, do they really need to go back to the page they were on? is there another option that could be as good or better?

<added>since Murdoch posted while I did

I am not sure of the SEO benefit or drawback of using GET params to only go to a form.

I don't think mod_rewrite is really a good first option as it is only a link to a single page/form, it would be better to design it so you don't need a rewrite

the included file would be good as the same as the database option but much faster. You would have to watch how much extra data you are lugging around

Murdoch

4:23 pm on Apr 14, 2008 (gmt 0)

10+ Year Member



I don't think mod_rewrite is really a good first option as it is only a link to a single page/form, it would be better to design it so you don't need a rewrite

I just meant in general, if his site is going to be mostly dynamic URLs then he might as well set up a rewrite for them, especially if he is in the early stages.

Yes it would be a bit overdoing it to create a rewrite for just this one instance though. Just throwing ideas out there for him :)

I suppose he could write an include script that always calls for $PHP_SELF and then does a list/split with the slash as the delimiter and then put it into an array that he calls later, but that's probably unnecessarily tedious. Might as well give him all the options though.

jatar_k

4:37 pm on Apr 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> site is going to be mostly dynamic URLs then he might as well set up a rewrite for them, especially if he is in the early stages.

true, good call