Solution 1 :

$_GET contains the keys / values that are passed to your script in the URL.
If you have the following URL :

http://www.example.com/test.php?a=15&b=umar

Then $_GET will contain :

array
  'a' => string '15' (length=2)
  'b' => string 'umar' (length=4)

Of course, as $_GET is not read-only, you could also set some values from your PHP code, if needed :

$_GET[‘my_value’] = ‘test’;

But this doesn’t seem like good practice, as $_GET is supposed to contain data from the URL requested by the client.

Solution 2 :

You’ll want to use GET

Looking at this URL:
http://localhost:8080/testsite/person?name=Tom

for an example in PHP

    if (isset(@$_GET['person'])) {
        $person = @$_GET['person']; 
    }

This will create a variable named $person that will be equal to “Tom”

Please sanitize what you GET though, because just accepting whatever a user inputs will leave you open to problems (i.e. sql injection).

Problem :

i’m new to this, but I am trying to pass parameters I get from the URL to a link on the webpage.

So I have this URL:

localhost:8080/testsite/person?name=Tom

On the page I have a link like this

<a href="localhost:8080/testsite/viewinfo?person=[ENTER Person name here.]>View info</a>

and I want to insert the value in the person parameter to the [ENTER Person name here]

such that the link is

<a href="localhost:8080/testsite/viewinfo?person=Tom>View info</a>

How can I do this?

Preferably not with Javascript

Thanks in advance

Comments

Comment posted by AndrewL64

What have you tried so far?

Comment posted by developer.mozilla.org/en-US/docs/Learn/Forms/…

developer.mozilla.org/en-US/docs/Learn/Forms/…

By