-3

Hi I have code PHP and I want to convert this code into symfony controller

Code PHP

header("Pragma: no-cache");
header("Cache-Control: private");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0", false);
header("Expires: 0");

echo "<html>";
echo "<body>";

echo "<form action=\"" . $url . "\" method=\"post\" name=\"form\" id=\"form\">";


echo "<input type=\"hidden\" name=\"key1\" value=\"" . $code . "\">";


echo "<input type=\"hidden\" name=\"key2\" value=\"$value\">";


echo ("</form>");

echo "<script language=\"JavaScript\">";
echo "document.form.submit();";
echo "</script>";

echo "</body>";
echo "</html>";

This code must redirect to another web site with the parametres posted is for authentification

this s my controller

class RedirectController extends Controller
{
/**
 * @Route("/redirect", name="redirect_root")
 */
public function redirectAction(Request $request)
{
     $data = array(
       'key1' => $code,
       'key2' => $value,
    );
    $url = 'http://login.php';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, true);


    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    $output = curl_exec($ch);

    curl_close($ch);

    return $output;
}

I use the response of HttpFoundation but alway The params dons't passed to login

user1844933
  • 3,296
  • 2
  • 25
  • 42
Mido
  • 41
  • 1
  • 4
  • 3
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Emii Khaos Sep 08 '15 at 10:33

1 Answers1

0

You should use HttpFoundation/RedirectResponse:

return new RedirectResponse('your_url');

or specific method (redirectToRoute('_route_name')):

return $this->redirectToRoute('your_route_name');
Alex
  • 1,073
  • 9
  • 20
  • but the url to submit is in another server it is not root symfony. – Mido Sep 08 '15 at 13:45
  • Ok, then redirectToRoute is not your case. Use RedirectResponse('url'), where url is any url you need to be redirected. Or use retutn $this->redirect('url'); – Alex Sep 08 '15 at 15:03