Nov 21, 2009

Index.php?pid=page&cat=category - Any idea on how to do this?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Index.php?pid=page&cat=category - Any idea on how to do this?

nightfox
I know this is a n00b question, but how do I make a website with URLs like that? I have seen it someplace before but I can't seem to find it.

If you have any ideas on how to do this, thanks! I am attempting to learn more PHP as my PHP scripting skills are VERY limited!

[N]F

Comment/Reply (w/o sign-up)

oncombeureum
index.php?pid=page&cat=category

i think it simple,

pid and cat is http variable,
page and category will be its values

both pid and cat is a same as when you deliver data using FORM and where PID and CAT is the text box.

to retrieve it.. there are many ways.

one's is :

$pid = $_POST['pid'];
$cat = $_POST['cat'];

Comment/Reply (w/o sign-up)

overture
I am not sure if you want to show a page of something based on the variables in the url, if you wanted to retrieve the PID and CAT vars then you would use this:

CODE
$_GET['pid']
$_GET['cat']


then if you wanted to show something based on those got vars you would do an/multiple IF statements. A better idea is to use the switch() case statement:

CODE
switch($_GET["pid"]) {
    default: include('index.php'); //the default page to be shown
    
    break;
    case "downloads": include('downloads.php'); //shows the downloads.php page

    break;
    case "news": include('news.php'); //shows the news.php page
}


the switch() case statement is basically used to replace multiple IF statements using the same var.

you would use $_POST when you are getting stuff from a form, but use $_GET or $_REQUEST when getting things from the URL.

 

 

 


Comment/Reply (w/o sign-up)

Hercco
Just bear in mind that you should always be using some sort of control structures when handling with the GET variable to prevent people from doing funny stuff with your site.

Ie. use a a switch structure like overture showed in his post.

DO NOT do this:

CODE
include($_GET['page']);

Comment/Reply (w/o sign-up)

vhortex
QUOTE (nightfox @ May 24 2005, 04:10 AM)
I know this is a n00b question, but how do I make a website with URLs like that? I have seen it someplace before but I can't seem to find it.

If you have any ideas on how to do this, thanks! I am attempting to learn more PHP as my PHP scripting skills are VERY limited!

[N]F
*


they are actually part of the GET form data which is automaticall inserted by the browser in the URL link (address bar) before jumping to the next page.

the page that will be juimp to is the one in the form action field.

CODE
     <form action='index.php' name='GSHOUT' method='GET' onsubmit="return shout_check('GSHOUT')">
     <input type='text' name='Post' class='forminput'> <input type='submit' name='submit' style='margin-bottom:1px' value='Shout' class='forminput'</form>


will draw a text input field with and a submit button

and when the submit button is pressed

will result in index.php?Post="text of Post""

"text of Post" if the same exact data you typed in the textfield..

NOTE: that will only be generated if you use the GET method and not the POST method. I guess you need to learn more from basic form html building.

one more thing, you can also explicitly append those at the webaddress but be sure that you have proper text reader for those infos so you can process them. anyway, you can always ignore all of them and nothing will happen to your program.

Comment/Reply (w/o sign-up)

vujsa
QUOTE (oncombeureum @ May 23 2005, 08:46 PM)
index.php?pid=page&cat=category

i think it simple,

pid and cat is http variable,
page and category will be its values

both pid and cat is a same as when you deliver data using FORM and where PID and CAT is the text box.

to retrieve it.. there are many ways.

one's is :

$pid = $_POST['pid'];
$cat = $_POST['cat'];
*


Actually, that should read:
$pid = $_GET['pid'];
$cat = $_GET['cat'];

The GET for method displays the varialenames and values in the url. The POST form method does not show the values in the url.

So you would never use a password or other sensitive information with the GET form method.

Here is a form that would create the url in the topic title:
CODE
<form method="GET" action="index.php">
<input type="text" name="pid" value="page"><br>
<input type="text" name="cat" value="category"><br>
<input type="submit"><br>
</form>


Here is an example of an index.php script that would use the form:
CODE
<?php
echo "The current page number is: " . $_GET['pid'] . "<br>\n";
echo "The current category is: " . $_GET['cat'] . "<br>\n";
?>


Would print:
The current page number is: page
The current category is: category


Hope this helps explain things. cool.gif

vujsa

Comment/Reply (w/o sign-up)

loganbest
if you clicked on a link to get to this page you would write the code as this:

lets say this code is in "index.php"
CODE
<?php      
$pid = $_GET['pid'];
$cat = $_GET['cat'];

if ($pid == "page" && $cat == "category") {

echo "The current page number is: page  and The current Category is: category";

}

?>
<html>
<head>
<title>Your Current page and Category</title>
</head>
<body>
<a href="index.php?pid=page&cat=category"> The link to the page and Category</a>
</body>
</html>


when you click on the link this will show up on the next page:
CODE
The current page number is: page  and The current Category is: category



correct me if I'm wrong but I'm pretty sure thats right

Comment/Reply (w/o sign-up)

Hercco
QUOTE (vujsa @ Jun 13 2005, 09:24 AM)
CODE
<?php
echo "The current page number is: " . $_GET['pid'] . "<br>\n";
echo "The current category is: " . $_GET['cat'] . "<br>\n";
?>


Would print:
The current page number is: page
The current category is: category


*



Problem with this is that someone could abuse it by requestion the page with some html code the GET values. For example index.php?page=%3Cimg%20src=%22http://www.server.com/goatse.jpg%22/%3E

which would add a <img tag your page with a picture you'd probably not want there. So if you do this, at least strip html tags before echoing the GET data. strip_tags() will do the job.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Indexphppidpageampcatcategory


    Looking for index, php, pid, pageandcat, category, idea

See Also,

*SIMILAR VIDEOS*
Searching Video's for index, php, pid, pageandcat, category, idea
advertisement



Index.php?pid=page&cat=category - Any idea on how to do this?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com