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

free web hosting
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

Reply

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'];

Reply

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.

 

 

 


Reply

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']);




Reply

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.


Reply

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

Reply

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

Reply

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.

Reply


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*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : index php pid pageandcat category

  1. [php] Index.php?section=xx&pag=yy - No MySQL or any other database (6)
  2. Index.php=blah Thingy .. ? - (2)
    ^^~ Ok.. I was wondering how to do that php thing where you go "index.php=blah" and it just comes up
    as something.. o_O >_ Ok.. It's like some php navigation thingy where all you need is like a
    word to describe the page.. and you stick it in.. ex : "staff" "index.php=staff" Er... and it goes
    to that page... @_@ I'm sorry if I got the description wrong too XD Anyway.. can anyone help?
    ;___;...



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

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




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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE