Jump to content
xisto Community
Sign in to follow this  
nightfox1405241487

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

Recommended Posts

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

Share this post


Link to post
Share on other sites

index.php?pid=page&cat=categoryi think it simple, pid and cat is http variable,page and category will be its valuesboth 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'];

Share this post


Link to post
Share on other sites

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:

$_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:

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.

Share this post


Link to post
Share on other sites

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:

include($_GET['page']);

Share this post


Link to post
Share on other sites

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

<{POST_SNAPBACK}>


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.

 

     <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.

Share this post


Link to post
Share on other sites

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

<{POST_SNAPBACK}>


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:

<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:

<?phpecho "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. :(

 

vujsa

Share this post


Link to post
Share on other sites

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"

<?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:
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

Share this post


Link to post
Share on other sites

<?phpecho "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

 

<{POST_SNAPBACK}>


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=%22 http://forums.xisto.com/no_longer_exists/

 

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.