繁体   English   中英

在没有Javascript的post方法中重定向到带有变量的url

[英]redirect to an url with variables in post method without Javascript

如果要满足条件,我想将页面重定向到另一个页面,例如samplepage1.php

$id = $_POST['id'];
$name=$_POST['name'];
if($max>$count){
//action on the same page
}
else{
//redirect to URL:index.php/samplepage2.php with the values $id & $name in POST METHOD
}

我需要一个解决方案,以便必须通过发布将值发布到“ samplepage2.php”,但严格不要使用javascript来实现自动提交(我不喜欢javascript的帮助,就好像用户可以在该浏览器中将其关闭)

@nickb的评论是正确的。 如果您的表单或其他任何处理javascript的内容都能使您的页面可以做什么和不能做什么,那么尝试弄清楚如何适应$ _POST毫无意义。

但是,一种解决方法是将该页面的$ _POST切换为$ _SESSION。

所以像这样:

$_SESSION['form1'] = $_POST;

当您到达下一页时(确保每页的开头都有session_start()),如果您确实愿意,可以将其切换回去。 不过,一旦完成,不要忘记unset($_SESSION['form1'])

尝试这个 :

$id = $_POST['id'];
$name=$_POST['name'];
if($max>$count){
//action on the same page
}
else{
$url = 'http://yourdomain.com/samplepage2.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'id='.$id);
curl_exec($ch);
curl_close($ch);$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'name='.$name);
curl_exec($ch);
curl_close($ch); 
}

如果您的服务器上启用了curl功能,则可以使用curl将POST数据发送到另一种形式,

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "index.php/samplepage2.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);

$data = array(
    'id' => 'value of id',
    'name' => 'value of name'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM