Skip to content

Instantly share code, notes, and snippets.

@agentcobra
Created June 12, 2018 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agentcobra/5bf4d805a50c621990aa0521081d93e6 to your computer and use it in GitHub Desktop.
Save agentcobra/5bf4d805a50c621990aa0521081d93e6 to your computer and use it in GitHub Desktop.
connexion snippet
<?php
if ($_POST) {
if($_POST['uni'] != $_SERVER['HTTP_ORIGIN'])
{
/**
* Redirect with POST data.
*
* @param string $url URL.
* @param array $post_data POST data. Example: array('foo' => 'var', 'id' => 123)
* @param array $headers Optional. Extra headers to send.
*/
function redirect_post($url, array $data, array $headers = null) {
$params = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data)
)
);
if (!is_null($headers)) {
$params['http']['header'] = '';
foreach ($headers as $k => $v) {
$params['http']['header'] .= "$k: $v\n";
}
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if ($fp) {
echo @stream_get_contents($fp);
die();
} else {
// Error
throw new Exception("Error loading '$url', $php_errormsg");
}
}
redirect_post($_POST['uni'], $_POST);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment