Jump to content

Url endings


ShaolinF

Recommended Posts

They are called GET variables and are created in a  multiple of ways.  First a form can be processed via get and list all input values in the url in the fashion of key=value&key2=value2.  Secondly they can be created from hyperlinks a big advantage to using them because you can create a link that has 1 page to a dynamic content. (like a photo gallery the id could be which image to display).  The final way is they can mainipulated by the user to make it what they want.  A danger to them for they could get info out of your mysql you don't want so be careful and only use when needed.  Fyi they also help with SEO because many serach engine can follow GET where POST/SESSIONs fail

Link to comment
Share on other sites

Create two pages as follows (left out the basic HTML):

 

page1.php:

<a href="page2.php?value=A">Value A</a>
<a href="page2.php?value=B">Value B</a>

 

page2.php:

<?php

  if (isset($_GET['value'])) {

    echo "You clicked Value $_GET['value']";

  } else {

    echo "You didn't click one of the links on page1!";

  }

?>

 

 

Link to comment
Share on other sites

Oh I see. So basically you can have dozens of links in your html and they all link to an IF statement in php file. Quite straight forward.

 

Not sure if you really get it. The links do not link to an if statement. The links simply link to a page AND include variables and their values within that link. The page that is being linked to can access those values using $_GET[variablename]

 

So, when using this link www.mypage.com/index.php?val1=a&val2=b

 

the page index.php would have two variable available to it:

 

$_GET['val1'] would equal 'a'

$_GET['val2 would equal 'b

Link to comment
Share on other sites

Oh I see. So basically you can have dozens of links in your html and they all link to an IF statement in php file. Quite straight forward.

 

Not sure if you really get it. The links do not link to an if statement. The links simply link to a page AND include variables and their values within that link. The page that is being linked to can access those values using $_GET[variablename]

 

So, when using this link www.mypage.com/index.php?val1=a&val2=b

 

the page index.php would have two variable available to it:

 

$_GET['val1'] would equal 'a'

$_GET['val2 would equal 'b

Thanks, very informative.

 

What if I had the following links:

 

<a href="page2.php?value=A">Value A</a>

<a href="page2.php?value=B">Value B</a>

 

When I click and it takes me to the IF statement, I want be able to differ between the value contained. For example, if 'value' is 'A' then echo A, whereas if 'value' is 'B' then echo b.

Link to comment
Share on other sites

This would be an easy example of a randnum.php file using $_GET and random numbers:

 

<?php
if (isset($_GET[randnum])) {
    $rand2 = rand(0,100);
    $message = "Your random number was $_GET[randnum]<br><br>To get a new one, click <a href=\"randnum.php?randnum=$rand2\">here</a>";
}
else {
    $randnum = rand(0,100);
    $message = "You do not have a random number  =(<br><br>To get a random number, click <a href=\"randnum.php?randnum=$randnum\">here</a>";
}
?>
<html>
<head><title>Random number!</title></head>
<body>
<?=$message?>
</body>
</html>

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.