【问题标题】:missing_GET_variables | is there a way determine where or what is the missing variable缺少_GET_variables |有没有办法确定缺失变量的位置或内容
【发布时间】:2015-07-18 19:20:36
【问题描述】:

在我的激活码中显示missing_GET_variables,我似乎找不到丢失的get 变量?在我的激活码中...

if ( isset($_GET['id']) && isset($_GET['u']) && isset($_GET['e']) && isset($_GET['p']) ) {

然后在底部有..

} else {
    // Log this issue of missing initial $_GET variables
    header("location: message.php?msg=missing_GET_variables");
    exit(); 
}

有人告诉我看我的注册页面,

    $message = '<!DOCTYPE html><html><head><meta charset="UTF-8">
<title>yoursite Message</title>
</head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;">
<a href="http://www.yoursite.com">
<img src="http://www.yoursite.com/images/logo.png"; width="36" height="30" alt="yoursite logo" style="border:none; float:left;"></a>yoursite Account Activation</div>
<div style="padding:24px; font-size:17px;">Hello '.$u.',<br />
<br />Click the link below to activate your account when ready:<br /><br />
<a href="http://www.yoursite.com/activation.php?id=&apos;.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br />
<br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';

他只给了我那个线索,但显然我似乎找不到它。我知道人们可能会或可能不会帮助我,这很好。但它值得一试不是吗,至少要问一下。

【问题讨论】:

  • 删除isset 包装器并找出答案。
  • 您知道您可以通过一次调用isset():if(isset($_GET['id'], $_GET['u'], $_GET['e'], $_GET['p'])) {来检查所有变量

标签: php forms variables get message


【解决方案1】:

您的$message 中有一个apos; html 实体,而不是'

用途:

$message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>yoursite Message</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.yoursite.com"><img src="http://www.yoursite.com/images/logo.png"; width="36" height="30" alt="yoursite logo" style="border:none; float:left;"></a>yoursite Account Activation</div><div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.yoursite.com/activation.php?id='.$uid.'&u='.$u.'&e='.$e.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';

【讨论】:

  • 还要避免过长的代码行,它们只会混淆您的工作并使您真正难以解决问题。
【解决方案2】:

前进的三种方式:

要么用这个来查看所有的$_GET:

}else{
    print_r($_GET);
    //header("location: message.php?msg=missing_GET_variables");
    //exit();
}

或者用这个来看看哪个坏了:

}else{
   $id=$_GET['id']
   $u=$_GET['u']
   $e=$_GET['e']
   $p=$_GET['p']
}

或设置默认值以主动处理该条件(代替整个 IF):

$id=(isset($_GET['id'])) ? $_GET['id']: [a good id];
$u=(isset($_GET['u'])) ? $_GET['u']: [a good u];
$e=(isset($_GET['e'])) ? $_GET['e']: [a good e];
$p=(isset($_GET['p'])) ? $_GET['p']: [a good p];

希望这会有所帮助!

【讨论】:

  • 既然我还是个初学者,那我应该把那个放在激活码下哪里呢?
  • 因为只有在出现问题时才会进入 Else,所以我建议你在 else 中使用 print_r
  • 当我发现什么变量被破坏时,我是否需要在我的注册页面中查看它丢失的位置?
  • 疑难解答可以有很多方向,但检查数据源是一个很好的起点。
猜你喜欢
  • 1970-01-01
  • 2013-10-05
  • 2020-02-22
  • 1970-01-01
  • 2016-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-25
相关资源
最近更新 更多