Query Strings - "&"<

windows

Guest
Hiya Folks,

A while back when I first started using query strings, I did it like this for my thankyou page:

When you want to contact me the URL would be?

../index.php?s=contact

And then when sent, I had the PHP script going to

../index.php?s=contact?ss=2

Then in the code I simply had:

case 'contact?ss=2':
include ('top.php');
include ('main/contact-2.php');
include ('bottom.php');
break;

And frankly, it worked great, but Scoutt warned me I would run into trouble. Well now I am redoing the whole web site and decided to fix the Query Strings while I'm at it. So how does the "&" symbol work? I want the improper URL:

index.php?s=contact?ss=2

To become:

index.php?s=contact&ss=2

I know there is a way, Scoutt told me to do it this way, but I seriously can't figure out how to do it. Obviously the first thing I tried was:

case 'contact&ss=2':
include ('top.php');
include ('main/contact-2.php');
include ('bottom.php');
break;

But then when you go to that URL, it simply goes to contact.php and ignores the "&ss=2". Does anyone understand this? When I learned Query Strings, I never learned anything about this symbol, but I see it all the time. Thanks a lot!

-Technelthere is nothing to learn.

index.php?s=contact&ss=2

the & is a seperator and that means that s=contact and ss=2 they are not togetherBut make sure that the & that appears in the HTML code output from the script is encoded as & so that the browser correctly displays it as an & instead of trying to look for and display two entities called &s and &ss for example.



.typoYeah Scoutt, but how do I get them to work. If you read my examples, they don't work. They just ignore the &.

Ok Giz, I changed it to this:

case 'contact&ss=2':
include ('top.php');
include ('main/contact-2.php');
include ('bottom.php');
break;

And it still doesn't work...

<!-- m --><a class="postlink" href="http://www.nitrox.uni.cc/nv/index.php?s=contact&ss=2">http://www.nitrox.uni.cc/nv/index.php?s=contact&ss=2</a><!-- m -->


.The forums seem to change the AMP string into a & automatically. In the code above, that's really the AMP (&A-M-P-;)like I said, they are seperate.

switch($_GET['s']){
case 'contact':
include ('top.php');
include ('main/contact-2.php');
include ('bottom.php');
break;
}

your switch can't do 2 variables.

switch($_GET['ss']){
case '2':
include ('top.php');
include ('main/contact-2.php');
include ('bottom.php');
break;
}Lol but Scoutt, if I do those two, I have two seperate URLS:

../index.php?s=contact
../index.php?ss=2

Instead of:

../index.php?s=contact&ss=2

I want to do this with other pages too. For example:

../index.php?s=games&ss=CS

I need them together in all one string!! You are the one that told me to do this! I see it does everywhere. In fact, it's done right on this forum.

newreply.php?s=&action=newreply&threadid=23972

One more example I found quickly:

index.php?user=test&offset=20

If you notice, they used it just like I need to. This is just a few examples, they are really everywhere

I also have another question. I read some search engine bots IGNORE query strings. When I heard this I looked like this: =:O So I did some researching. I looked at the CNN web site. Sure enough, they do not use query strings. Here's a link from the site:

<!-- m --><a class="postlink" href="http://www.cnn.com/2003/ALLPOLITICS/09/30/wilson.cia/index.html">http://www.cnn.com/2003/ALLPOLITICS/09/ ... index.html</a><!-- m -->

I know that their links and stuff on the side change often with new breaking news and stuff, so how do they do it with no frames, PHP, or iframes????? And is this true about query strings?

Thanks,

Technelok, listen because this is the last time I can tell you, next time I will just kill ya :P

no you don't have to use 2 different urls. the variable "s" and "ss" can be used in the same page. like this site does. it is real easy. your way will not do so you need to change your way of loading a page if you want 2 different variables. if you want one variable then you need to take the & out of the equation. I just showed you how to access both variables. not that you had to use them.

index.php?user=test&offset=20
they don't use it like you want. they use the variables seperatly. you just need to figure out what you want to load if the variable "ss" comes in. you can also send it through the include if you want. again you need to change your way of loading the includes depending on variables.

about search engines, hey that is life. you want to make a page that doesn't have query string then don't use them, but you can just use frames. the way cnn does it is that it creates a cached page from the query strings, that is my guess.Yes, some busy sites create cached copies of 'dynamic' pages, to decrease load on the server, but if you have to have dynamic data on each page, say a user name or so, caching the pages isn't really an option.
That's where the apache module mod_rewrite comes into play.. very handy thing.
Reference here:
<!-- m --><a class="postlink" href="http://httpd.apache.org/docs/mod/mod_rewrite.html">http://httpd.apache.org/docs/mod/mod_rewrite.html</a><!-- m -->

Basically, you can call a site with the URI

<!-- w --><a class="postlink" href="http://www.domain.com/articles/2003/198.html">www.domain.com/articles/2003/198.html</a><!-- w -->

and you would think that this is a static page, but in fact mod_rewrite steps in before the request is processed by the server, and rewrites the URI to something like this:

<!-- w --><a class="postlink" href="http://www.domain.com/index.php?area=articles&year=2003&id=198">www.domain.com/index.php?area=articles&year=2003&id=198</a><!-- w -->

Of course, this requires Apache.. but maybe there are similar solutions for other servers. Anyway, search engines will be fooled to thinking the pages are static, and index them. For restricted pages, you're better off using normal query strings, or just telling the 'robots' where to search and where not to.

Here's a very simple tutorial, if the ref doc is a bit too heavy for you (it was for me). ;)

<!-- m --><a class="postlink" href="http://www.phpfreaks.com/tutorials/23/0.php">http://www.phpfreaks.com/tutorials/23/0.php</a><!-- m -->

But it requires a profound understanding of how query strings work.. so you might want to read up further in that area ;)

I hope it helps.Alright..!!!

no you don't have to use 2 different urls. the variable "s" and "ss" can be used in the same page. like this site does. it is real easy. your way will not do so you need to change your way of loading a page if you want 2 different variables. if you want one variable then you need to take the & out of the equation. I just showed you how to access both variables. not that you had to use them.


Ok, I finally understand what you mean. My problem is that I this is simply a thankyou page for the send form. I don't want the contact form to still be on there, I want it to forget about that. Same with the other pages. For games, I want index.php?s=games&ss=dod to include the main gaming.php page, I want to just include the Day of Defeat game, but since DoD is a game and it goes in the games section, I want it on the gaming URL string. I had it with "index.php?s=games?ss=dod" but ssccouuttt (I always blame him, hehe) told me not to :P But I now understand the concept behind why people use the "&", but I stil would like to use it without being inconvenienced.

about search engines, hey that is life. you want to make a page that doesn't have query string then don't use them, but you can just use frames. the way cnn does it is that it creates a cached page from the query strings, that is my guess.

I'm not to worried I guess.

Rydberg: Yeah, I'm on an apache server. But man, those Apache and PHP docs that they make, gosh, could they make them any more complicated, heh. Thanks for the information, I'll take a look at the SIMPLE tutorial }:-)then you best bet is to do this

switch($_GET['s']){
case 'game':
include ('top.php');
include ('main/game.php?".$_GET['ss']."');
include ('bottom.php');
break;
}

that way when a url comes like so

index.php?s=games&ss=dod

it will see "s" to load the games.php file and then in that file you want to send "ss" to it so it loads DoD when that comes up.

is that what you want.Now I have:

case 'contact':
include ('top.php');
include ('main/contact.php');
include ('bottom.php');
break;
case 'contact':
include ('top.php');
include ('main/contact-2.php?".$_GET['ss']."');
include ('bottom.php');
break;

Parse error on the line:

include ('main/contact-2.php?".$_GET['ss']."');

??


-Technelwhat I don't understand is why are you including the same files in the same case statement? if the same files are being included than why have have them in the cases?

also you have the same case statements which won't work.

try this

include ('main/contact-2.php?{$_GET['ss']}');I redid a bunch of things and realized that this would be all I needed the & for, so I just did:

index.php?s=contact:2

It looks proffessional :D I have another problem though, see my new topic.why do you need the 2? can't you just use index.php?s=contacts=contact is the form to send mail
s=contact:2 is the thankyou message

Didn't you know that? BTW I changed it. It's now:

interact.php?s=contactno I didn't know that. you could have done it another way and it would have been easier. insted of s=contact:2 or whatever you could have just did s=thankyou and then loaded the proper page according to that.

so you had
s=contact
s=thankyou

and those would have load the correct page in your switch statement.

but it doesn't matter I guess :P
 
Back
Top