Reputation: 6635
I need to pass information via a URL to a PHP function that parses the received data.
So basically when they click on the specific link, it will go to the specific page, but also send through the arguments and values for the waiting PHP function to parse them and depending on what the values are do specific functions.
eg: http://www.mydomain.com/arg=val&arg=val&arg=val (not sure about how I built that URL either)
Upvotes: 0
Views: 1697
Reputation: 146460
Generate URL:
<?php
$data = array(
'first_name' => 'John',
'last_name' => 'Doe',
'motto' => 'Out & About',
'age' => 33
);
$url = 'http://example.com/?' . http_build_query($data);
?>
Pick data:
<?php
$data = array();
if( isset($_GET['first_name']) ){
$data['first_name'] = $_GET['first_name'];
}
// Etc.
?>
Upvotes: 2
Reputation: 816760
Your can access the parameters via the array $_GET
.
Note: in your example, you basically send just one paramter. PHP cannot handle multiple parameters with the same name.
You can build URLs that contain data from variables using string concatenation or string parsing.
If you browse the web, you will recognize, that the query string (the parameters) always follow a ?
in the URL. Read about URLs and the URI syntax.
Probably also interesting for you to read: Variables From External Sources which describes how to deal with data sent via POST or GET or cookies.
Upvotes: 3
Reputation: 3938
You can build the URL like the following (note the ? )
http://www.domain.com/page.php?arg1=val&arg2=val
Then in your PHP using the following code by using REQUEST you can get the data from either GET or POST parameters.
$arg1 = $_REQUEST['arg1'];
Upvotes: 0
Reputation: 799014
Parameters passed in the query string are available in the $_GET
superglobal array.
Upvotes: 1