Send and receive data

Sending and receiving data using the GET and POST methods are easy when using the SMRequest class.

$data = new SMKeyValueCollection();
$data["name"] = "Casper Jacksson";
$data["age"] = "29";

// Send and receive data as if an HTML Post Form was used
$postResponse = SMRequest::Post("http://domain.com/test.php", $data);

// Send and receive data as if data was specified in URL:
// http://domain.com/test.php?name=Casper Jacksson&age=29

$getResponse = SMRequest::Get("http://domain.com/test.php", $data);
The SMRedirect class can be used to perform redirects, allowing a request to be transfered to another URL.

// The PHP way - do not use this solution
header("location: http://google.com");

// The Sitemagic way
SMRedirect::Redirect("http://google.com");
In case redirecting is needed, use the Sitemagic solution. The Redirect function will make sure all data is properly committed, before redirecting the user to the specified address.


SMRequest class

Function Return type Description
::Post($url:string) String Perform Post request to specified URL - no data is transfered. Response is returned.
::Post($url:string, $data:SMKeyValueCollection) String Post the supplied data to the specified URL. The response is returned.
::Get($url:string) String Perform Get request to specified URL - no data is transfered. Response is returned.
::Get($url:string, $data:SMKeyValueCollection) String Perform Get request with the data supplied to the specified URL. Response is returned.


SMRedirect class

Function Return type Description
::Redirect($url:string)
Re-locate user to specified URL. All data transactions are committed before redirecting.