[英]redirect to an url with variables in post method without Javascript
I want to redirect my page to another if a condition is satisfied say, samplepage1.php 如果要满足条件,我想将页面重定向到另一个页面,例如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
}
I need a solution so that the values must be posted to the 'samplepage2.php' through a post, but strictly not using javascript to achieve auto submission (I dont prefer the help of javascript as if user may turn it off in there browser) 我需要一个解决方案,以便必须通过发布将值发布到“ samplepage2.php”,但严格不要使用javascript来实现自动提交(我不喜欢javascript的帮助,就好像用户可以在该浏览器中将其关闭)
@nickb is right with his comments. @nickb的评论是正确的。 If your forms or anything else handle javascript and would make a difference what your page can and cannot do, then it's pointless trying to figure out how to accomodate the $_POST.
如果您的表单或其他任何处理javascript的内容都能使您的页面可以做什么和不能做什么,那么尝试弄清楚如何适应$ _POST毫无意义。
However, one way of handling this is switch your $_POST to $_SESSION for that page. 但是,一种解决方法是将该页面的$ _POST切换为$ _SESSION。
So something like: 所以像这样:
$_SESSION['form1'] = $_POST;
And when you reach the next page (make sure you have session_start() at the beginning of each page), you can switch it back if you really want to. 当您到达下一页时(确保每页的开头都有session_start()),如果您确实愿意,可以将其切换回去。 Don't forget to
unset($_SESSION['form1'])
once you're done with it though. 不过,一旦完成,不要忘记
unset($_SESSION['form1'])
。
Try this : 尝试这个 :
$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);
}
if curl
is enabled on your server than you can use curl to send POST
data to another form, 如果您的服务器上启用了
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.