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
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
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
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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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