Jump to content

$_GET


justAnoob

Recommended Posts

If you have multiple values in your URL string you can get them all.. $_GET has a limit to how many bytes it can hold but something like this.

index.php?var1=tetst&var2=sdfsdf&var3=wfgdfgdfg

can be access like this

$var1 = $_GET['var1'];
$var2 = $_GET['var2'];
etc...

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987500
Share on other sites

Of course, Take into account you enter this url:

www.example.com/index.php?page=1&style=blue

 

In PHP, you can find them using:

if (isset($_GET['page'])) { 
  echo 'Page ID is set!, ID = ' . $_GET['page'];
} else { 
  echo 'Please enter an ID';
}

if ($_GET['style'] == 'blue) {
   echo '<div style="background-color:blue;"> A div! </div>';
}'

 

It's recommended to use isset() to find out if they're entered or not, or else it may return an error if you ask for it and it's not there.

 

http://www.php.net/manual/en/reserved.variables.get.php

 

Also, make sure you sanitize anything being outputted via GET variables.

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987502
Share on other sites

you can use the $_GET to get different values from the url, I am not sure about sending.

 

I believe it is possible since The Global variable $_GET only gets in charge of making the variable value available though out the whole script what you call is the variable with different name not the super Global $_GET.

 

you call the variables values through the $_GET

 

 

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987503
Share on other sites

you can use the $_GET to get different values from the url, I am not sure about sending.

 

I believe it is possible since The Global variable $_GET only gets in charge of making the variable value available though out the whole script what you call is the variable with different name not the super Global $_GET.

 

you call the variables values through the $_GET

 

You can of course assign one:

//index.php?arg=test
$_GET['arg'] = "Foobar";
$arg = $_GET['arg']; // Will echo"FooBar"

 

GET arguments are useful when the user needs to return to a specific setting on a page, such as ID number.

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987507
Share on other sites

Ok,

The reason I ask is cause the page that loads has a URL like the following

http://www.mysite.com/category.php?selecting=Video Games

Video Games can differ depending on what category they choose on the previous page.

 

Then, there is a pagination script with page numbers.

$targetpage = "mypage.php";
<a href='$targetpage?page=1'

 

So I would have to edit my $targetpage var ?

 

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987508
Share on other sites

I get an error on this line

$page = mysql_escape_string($_GET['page']);

when my url reads like this already

http://www.mysite.com/category.php?selecting=Video Games

This is hard to explain

 

If you're wanting to get 'Video Games', than use this:

$page = htmlspecialchars($_GET['selecting']);

Note escaping data does not sanitize it, only for SQL queries. HTMLspecialchars prevents any input that is not wanted (XSS forgery etc.).

 

Remember, $_GET['whatever'] is url.php?whatever=foobar. If it doesn't exist, the GET statement will throw that error.

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987528
Share on other sites

Sorry for the confusion, let me try to explain again

 

Page 1:

has a list of categories

when user clicks on one of the categories, they are taken to a new page, which would look like this

http://www.mysite.com/category.php?selecting=Video Games

 

The above URL would be called page 2

 

Page 2:

when page 2 is diplayed, there may be 500 video games to be listed which brings in my pagination.

my pagination script is having probs working with my url from above because there is alreay a variable in it.

Here is some of my pag script

$targetpage = "category.php";

$page = mysql_escape_string($_GET['page']);

<a href='$targetpage?page=

Of course the page= could be a number of variables within my pagination script.

I'm not sure but it almost seems like my $targetpage var should be someting like

category.php?selecting=video games .....  this way my pagination script variables come after the complete url of whatever category was chosen.

 

Does any get this?

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987534
Share on other sites

$targetpage = "category.php";
$page = htmlspecialchars($_GET['page']);
<a href="$targetpage?selecting=".$_GET['selecting']."&page=$page">

 

Do you mean that? It'll retain the 'selecting' variable and ADD the page variable at the end, as the pagination script asks..

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987539
Share on other sites

Instead of changing all my hrefs in my page, could I just change the target page variable to something like

 

$targetpage = 'category.php?selecting=' . $_GET["selecting"] . ' & ';

 

Yes, if the pagination script adds to the end of the url, that should work fine. But you have to remove the spaces around the ands.

$targetpage = 'category.php?selecting=' . $_GET["selecting"] . '&';

Link to comment
https://forums.phpfreaks.com/topic/187003-_get/#findComment-987547
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.