I want to redirect my page to another if a condition is satisfied say, 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)
@nickb is right with his comments. 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.
However, one way of handling this is switch your $_POST to $_SESSION for that page.
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. Don't forget to unset($_SESSION['form1'])
once you're done with it though.
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,
$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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.