Katalyst
Katalyst

Reputation: 19

getting php variable from url

Is it possible to get php variables from the url?

e.g

test.php contains;

     $value1 = 45;
     $value2 = 50
     $value3= 43

Would it be possible to retrieve those 3 values only using a URL to the test.php file?

       e.g www.test.com/test.php?x=value1?y=value2?z=value3  

So if a program sent a request of some sort to that url, it would return the 3 values

Upvotes: 1

Views: 139

Answers (3)

Cybs
Cybs

Reputation: 57

This can easily be done, use

<?php
$fromurl = $_GET['var'];
?>

then in your browser domainorip/yourfile.php?var=something obviously change domainorip to your server address and yourfile.php to your php document the value will be stored in the $fromurl variable

Upvotes: 3

aaaaahhhhh
aaaaahhhhh

Reputation: 151

How do you want the URL to be returned to your application? Of cause you can do a

redirect to test.php?x=value1&y=value2&z=value3

whenever there's access to the test.php. But you gonna make sure your application can receive the redirect URL though.

The better way of doing this is actually through SOAP webservice i think, especially if you're going to have more of these communication between PHP and native application. It can be as simple as something like this in test.php (with webservice setup)

function getValues($x)
{
    if(isset($x))
    {
        $result+=$value1;
    }
return $result;
}

Upvotes: 0

Why is that hard ?

$value1 = $_GET['x']; /"prints" value1

or alternatively you can make use of parse_url

Upvotes: 2

Related Questions