将数据从html页面发布到php文件,并从php文件重定向到主页


posting data from an html page to a php file and redirect from the php file to the homepage

我希望将数据发布到datahouse.php中,后者现在将数据提交到服务器并重定向到索引页面,而不在页面上显示datahouse.hp文件。。

register.html

<form method="POST" action="DataHouse.php">
<input type="text" name="username" value="tempapilogin" /><br>
<input type="password" name="password" value="aF4YMjuQ" /><br>
<input type="text" required name="name" placeholder="Full Name" /><br>
<input type="email" required name="email" placeholder="EMail Address" /><br>
Gender:
    <fieldset data-role="controlgroup" data-mini="true" >
        <input type="radio" name="gender" id="radio-mini-1" value="MALE" />
        <label for="radio-mini-1">MALE</label>
    <input type="radio" name="gender" id="radio-mini-2" value="FEMALE" />
        <label for="radio-mini-2">FEMALE</label>
        </fieldset>     
Birthday: <input type="date" required name="birth_date" placeholder="dd/mm/yyyy" />
Phone Number: <input placeholder="02xxxxxxxx" type="tel" name="phone_number" />
Facebook ID: <input type="email" name="facebookid" />
<table>
<tr>
<td><input type="submit" name="submit" value="Submit"/></td>
</tr>
</table>
</form>

下面是将数据发布到服务器的php文件,然后必须重定向到index.html页面。

datahouse.php

<?php
//Index.html page to redirect to-->
header("Location: c:'Users'Selorm'Desktop'Maxwell-Internship @ Nandimobile'connect'Index.html");
//create cURL connection
$curl_connection = curl_init();
//create array of data to be posted
array{$post_items[] = 'Username='.strip_tags($_POST['username']);
$post_items[] = 'Password='.strip_tags($_POST['password']);
$post_items[] = 'Email='.strip_tags($_POST['email']);
$post_items[] = 'Gender='.strip_tags($_POST['gender']);
$post_items[] = 'Birthday='.strip_tags($_POST['birth_date']);
$post_items[] = 'Phone Number='.strip_tags($_POST['phone_number']);
$post_items[] = 'Facebook ID='.strip_tags($_POST['facebookid']);}
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$birth_date = $_POST['birth_date'];
$phone_number = $_POST['phone_number'];
$facebookid = $_POST['facebookid'];
//traverse array and prepare data for posting (key1=value1)
foreach ( $_POST as $key => $value) {
    $post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//set options and set data to be posted
curl_setopt_array($curl_connection, array(
 CURLOPT_CONNECTTIMEOUT => 30,
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_SSL_VERIFYPEER => false,
 CURLOPT_AUTOREFERER => true,
 CURLOPT_FOLLOWLOCATION => true,
 CURLOPT_POSTFIELDS => array(
 username => 'username',
 password => 'password',
 name => 'name',
 email => 'email',
 gender => 'gender',
 birth_date => 'birth_date',
 phone_number => 'phone_number',
 facebookid => 'facebookid' )
 ));
//perform our request
$result = curl_exec($curl_connection);
$result = json_decode($json);
foreach ($result as $key => $value)
{
 echo $key. ':' ;
}
print_r(curl_getinfo($curl_connection));
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . 
curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
exit;
?>

我猜问题是页面重新定位,但没有发布任何内容。

datahouse.php在遇到时立即重定向

header("Location: c:'Users'Selorm'Desktop'Maxwell-Internship @ Nandimobile'connect'Index.html");

把它移到最后,在它之前不要输出任何东西。如果你回显任何东西,你会得到一个错误,告诉你已经发送了头。

您需要将重定向发送到某个web服务器上可见的URL。

无法将客户端重定向到服务器硬盘上的任意文件路径。