2014-12-19 91 views
1
<?php 
    error_reporting(0); 
    if(isset($_POST['submit'])){ 
     $additionalIDs = array("williamhew","anthon9","geroyi"); 
     $rA = array_rand($additionalIDs,1); 
     $merchantNick = ".membership.com"; 
     $gen_link = $additionalIDs[$rA].$merchantNick; 
     header("Location: http://$gen_link"); 
    } 
?> 

<input type ="submit" name="submit" ></input> 

我不知道为什么它不会重新定向后,我点击提交。这段代码有什么不妥? 我需要你们的帮助:(PHP没有重定向后subminision

编辑:

使用,这也不能重定向,

<?php 
    error_reporting(E_ALL); 
    if(isset($_POST['submit'])){ 
     ob_start(); 
     header("Location: http://www.facebook.com"); 
     exit; 
    } 
+0

试图标题( “位置:http://”。$ gen_link); ? – 2014-12-19 08:12:24

+0

@MarcoMura,我已经试过它,即使与http://www.facebook.com也无法正常工作。 – FreedomPride 2014-12-19 08:13:01

+4

您的提交元素不在表单标签中。 – 2014-12-19 08:14:49

回答

1

尝试包INPUT元素在<form>标签用PARAM方法= “后”,像这样:

<form method="post"> 
     <input type ="submit" name="submit" /> 
</form> 

顺便说一下, INPUT是一个自动关闭标签,因此您可以这样写:<input type ="submit" name="submit" />

0

你的头之前无论是输出的东西,在这种情况下,它会不定向。

记住,标题()必须被称为是 发送的任何实际输出之前,无论是由正常的HTML标记,空行的文件,或者从PHP。 使用include或require, 函数或其他文件访问函数读取代码并在调用header()之前输出空格或空行 是非常常见的错误。使用单个PHP/HTML文件时存在相同的问题 。

或者链接本身无效。这不是没有问题的。

0

你只需要添加

<form method="post"> 
    <input type ="submit" name="submit"></input> 
</form> 
+0

对啊....... :) – Dhruv 2014-12-19 08:21:47

0

试试这个

使用了window.location而不是头部位置

<?php 
echo "<script>window.location.href='index.php'</script>"; 
} ?> 
+0

对php业务使用javascript解决方法通常不是很好的做法。 – Rimble 2014-12-19 10:26:31