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

时间:2013-07-26 13:09:16

标签: php html

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

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;
?>

2 个答案:

答案 0 :(得分:2)

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

datahouse.php遇到<​​/ p>时会立即重定向

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

将其移至最后,不要输出 ANYTHING 。如果您回复任何内容,则会收到错误消息,告知您已经发送了标题。

答案 1 :(得分:1)

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

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