PDA

View Full Version : Need Help On PHP


Averon Design
11-22-2004, 07:29 PM
I have an question about php. I am trying to learn it. But my question is this. I have found an web site that has php and i was wondering if anyone knows how to do this. This site is http://www.pacificcrestcabinets.com/index.php

But the thing on the site is. if you go to products on the menu it goes to
http://www.pacificcrestcabinets.com/index.php?l1=products&l2=door_styles
this. I want to do the same thing on my site but not sure how to do this. I hope someone can help me thanks

Zykaz
11-22-2004, 07:53 PM
Correct me if I'm wrong, but you're talking about the extra parts in the URL (?l1=products&l2=door_styles)?

The part after the question mark is called the query string, and it's actually HTML, not PHP. Whenever you send something in a form using the GET method, it puts that information in the query string. That's how the form information _can_ be retrieved later.

Check out w3schools.com for HTML tutorials on forms, and it should describe both the POST and GET methods.

Averon Design
11-22-2004, 08:02 PM
yes your are right on the part about the (?l1=products&l2=door_styles)
But why would they us an forum for that??? And how would they do that.

Zykaz
11-22-2004, 08:29 PM
It's a lot like if you're browsing around this forum, and look at the filename as you go around, each page has a different number. If you just change the number, you go to a different page.

It's used because it's a bit more organized.

Basically, you'd set the query string with HTML, then do something like this in PHP:


<?
if ($querystring == 'pagename') { //if string = "whatever" : go there
require ('pagelink.php');
}
?>


Then you'd just set either switch statement, or some if's/else's.

Averon Design
11-22-2004, 09:58 PM
How would i do an switch statement for that that is where I am getting lost at.

Zykaz
11-22-2004, 10:42 PM
Like this:


<?
switch ($querystring) {
case 'name' :
require('pagelink.php');
break;
case 'second' :
require('secondpagelink.php');
break;
default :
require('thispage.php');
break;
}
?>

Averon Design
11-22-2004, 10:47 PM
I am lost know
would this make it to have 2 vars in it????

like ?pg=test&pg1=test1

Zykaz
11-22-2004, 10:58 PM
No. That'll just work for one.

I figured that you knew how to get the query string in $querystring, and how to set it. If you want those explained, just let me know.

You don't _have_ to have two vars in the query string. You'd have to set them both, then add checking the second after the & in the switch.

They're mostly just conditionals. Because it's just passing the vars along from another page, then the switch's or if's check the query string. Really, they're not necessary, and some people don't like them. But, they can sometimes be helpful.

Averon Design
11-22-2004, 11:05 PM
I want to learn how to have 2 vars i am not sure about the query string and how to set it up. I am learning. but if you can teach me how to do that with 2 vars that would be great. I my site would like like to have 2 vars like ?pg=aboutus&pg2=pictures. it would make it look nice in the address bar and i think people would liek to see that too.

Zykaz
11-22-2004, 11:26 PM
Honestly, it's not a great thing to have unless you have a real good reason for it. It adds a lot of extra programming, for the extra conditionals, and added security, along with the added possibility of different kinds of web hacking-based injection techniques that could be used to exploit your site. I don't think the address bar looking good is a great reason for the added work.

Think about it, and if you still want to, I'll post some code and explanations tomorrow.

Averon Design
11-22-2004, 11:30 PM
I just want to learn how to do that. That is it if i dont use it on my site then I will know how to use it for something else, and if i ever need to use it.

Zykaz
11-22-2004, 11:31 PM
Good reason. :)

I may have time later, but if not, expect for a new post sometime tomorrow afternoon.

Averon Design
11-22-2004, 11:35 PM
Ok Thanks here is my email too sales@averondesign.com

Zykaz
11-23-2004, 09:32 PM
This is probably the easiest, most toned down way you can do it with two,...


<?php
ini_set("register_globals", "on");
$firststring = $_GET['firstquery']; //get the first string set on the last page
$secondstring = $_GET['secondquery']; //get the other one
if (($firststring == 'one') && ($secondstring == 'two')) {
//do something...
} else if (($firststring == 'one') && ($secondstring == 'three')) {
//do something else...
} else if (($firststring == 'two') && ($secondstring == 'two')) {
//blah...
} else if (($firststring == 'three') && ($secondstring == 'two')) {
//you get the point...
}
?>


It would, however, keep going, for each possibility.

Three other things:
1. In the previous page, you'd have to set $firststring and $secondstring, in an href, or anywhere.
2. There _is_ a predefined variable, $QUERY_STRING, it should be, that you can use to go through the query string, but I think this is easier.
3. I didn't test out this code, so I'm not aware of any errors.

I'm not going to tell you about the possibilities a hacker has with the query string, it's too much to explain. You can do a google search on SQL and PHP injection if you want to know, though.

Averon Design
11-24-2004, 05:30 PM
ok how would i add that in the script. Could you use the switch statement and the case. And how would you make it for hacker cant get into it.

Zykaz
11-24-2004, 11:17 PM
You would just add it, but you have to customize it to how you want it. Using switch statement would be harder, because of checking both the variables.

And as I said, I'm not going to describe the security measures you have to take. It's too much for me to type up. Do a google search for SQL and PHP injection, and research that.