1

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

4
  • Your question seems sort of backwards, or confusing. You're trying to extract the values from the file, and send them back to the requesting file? Not set the values within the file from the URL, correct? Commented Jan 14, 2014 at 4:43
  • Probably what you should do is have that PHP file print JSON Commented Jan 14, 2014 at 4:44
  • So for the confusion. Basically i have an application that cannot process PHP by itself so I will have to using an extension like curl or socket to access the php file and retrieve the information Commented Jan 14, 2014 at 5:25
  • What are you retrieving it into? A browser? Commented Jan 14, 2014 at 16:04

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

Why is that hard ?

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

or alternatively you can make use of parse_url

1 Comment

I want to get the values from the url itself if possible. the calling application doesnt do PHP.
0

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.