您好我有PHP代码,我想将此代码转换为symfony控制器
代码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>";
此代码必须重定向到另一个网站,其中发布的参数是用于身份验证
这是我的控制器
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;
}
我使用HttpFoundation的响应但总是没有传递给登录
答案 0 :(得分:0)
你应该使用HttpFoundation / RedirectResponse:
return new RedirectResponse('your_url');
或特定方法(redirectToRoute('_ route_name')):
return $this->redirectToRoute('your_route_name');