2011-06-01 71 views
0

我试着写这个剧本说,如果电子邮件valied插入到数据库和重定向,否则错误消息重定向只有我的重定向不工作,我不是可怕的PHP伟大和还在读书了关于这个问题,所以ID欣赏任何建议,在此先感谢!PHP头位置

<?php 

$userid = $usersClass->userID(); 
$user_email=$_POST['email_upd']; 

if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)) 
{ 
header('Location: http://www.mysite.co.uk/mytwitter.php?msg=invalid'); 
} 
else 
{ 
mysql_query(" UPDATE produgg_users SET email='$user_email' where produgg_users.id = ".$usersClass->userID()) or die(mysql_error()); 
header('Location: http://www.mysite.co.uk/mytwitter.php?msg=success'); 
} 

?> 

对不起,不说明什么不顺心,发生了什么事是我的网页心不是在标题重定向回页面(位置)

我现在已经启用了错误报告和IM仍然只看到一个白色的页面,继承我的整个页面代码。

<?php 

error_reporting(E_ALL); 
require 'config.inc.php'; 


?> 

<?php 

$userid = $usersClass->userID(); 
$user_email=$_POST['email_upd']; 

if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)) 
    { 
    header('Location: http://www..co.uk/mytwitter.php?msg=invalid'); 
    } 
else 
    { 
    mysql_query(" UPDATE produgg_users SET email='$user_email' where produgg_users.id = ".$usersClass->userID()) or die(mysql_error()); 
    header('Location: http://www..co.uk/mytwitter.php?msg=success'); 
    } 

?> 
+2

不回答你的问题,但你需要时刻'死()'头重定向后,你的代码很容易受到[SQL注入](http://php.net/manual/en /security.database.sql-injection.php) – 2011-06-01 19:07:45

+0

尽管如此,您应该描述究竟出了什么问题。 – 2011-06-01 19:08:05

+0

佩卡嗨,我意识到它目前脆弱的注入式攻击,即时通讯在我打算以后整合,或者是这难道不是处理事情的最佳途径一刻起,阅读起来? – Liam 2011-06-01 19:08:54

回答

0

我设法得到它的工作使用下面的代码,我已经重写它基于我读过关于SQL注入和它工作得很好,我会很感激这个任何建议,谢谢!

<?php 

require 'config.inc.php'; 

$userid = $usersClass->userID(); 
$user_email=mysql_real_escape_string($_POST['email_upd']); 

if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $user_email)) 
{ 
    mysql_query(" UPDATE produgg_users SET email='$user_email' where produgg_users.id = ".$usersClass->userID()) or die(mysql_error()); 
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=/mytwitter.php?msg=email updated\">"; 
} 
else 
{ 
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=/mytwitter.php?msg=email error\">"; 
} 

?> 
0

这应该工作,但要确保你没有头的方法之前的任何代码,当我说的代码我的意思是,在任何其他文件从PHP或HTML标签的输出,这需要先执行, ,但你也需要确保重定向后的代码没有被执行,用exit退出;

header(.... 
exit; 
+0

没有运气........ – Liam 2011-06-01 19:20:46

+0

这应该真正发挥作用,但检查其他浏览器,我知道FF一些插件可以禁用页面重定向... – 2011-06-01 19:31:52

0

您可以发布您的完整脚本吗? Senad说的是真的:如果你的脚本写任何东西到输出缓冲区,任何header();将不再工作。根据你给出的代码,没有什么会被写入输出缓冲区(除非你得到一个mysql错误,你没有告诉我们,我认为不是这种情况)。

而且,也没有必要使用,然后重新打开它。只是FYI。