0

我试图向 PHP 文件发送一个值,但是当我检查时,这个值变成了null.

我通过以下方式发送值:user_login.php?p_action=New_User

user_login.php 的代码是:

require("include/session_inc.php");
require("include/user_handling_inc.php");
require("include/db_inc.php");

start_Session(false, false);

switch ($p_action) {
case 'Login': {
 $l_flag = verify_User($p_in_username, $p_in_password);
 if ($l_flag == "Not_Found") {
     $l_flag = "New_User";
 }
 break; 
}
case 'Save_Profile': {
$l_flag = "Save_Profile";
    break;
}
case 'New_User':
$l_flag = "New_User";
    break;
case 'Create_New_User':
$l_flag = "Create_New_User";
}

switch ($l_flag) {
    case 'New_User': {
    include "include/user_new_inc.php";
    break;
  }
case 'Save_Profile': {
    load_User_Data(" username = '$p_in_username' ", false);
    include "include/user_profile_save_inc.php";
    break;
  }
case 'Wrong_Password': 
    echo "Wrong Pass";
    break;
case 'OK': 
    load_User_Data(" username = '$p_in_username' ", true);
    store_User_Cookie($g_userdata->user_id);
    include "include/user_profile_inc.php";
    break;
case 'Create_New_User':
$l_user_id = create_New_User ($p_in_username, $p_in_email, 'Y');
    if ($l_user_id != -1) {
        store_User_Cookie($l_user_id);
        echo "Success !! <br><br> \n";
        echo "<a href\"/index.php\"> Back to Main </a>";
     }
break;
}
4

3 回答 3

1

你需要像这个朋友一样制作代码

switch ($_GET["p_action"]) {
case 'Login': {
 $l_flag = verify_User($p_in_username, $p_in_password);
 if ($l_flag == "Not_Found") {
     $l_flag = "New_User";
 }

那好给你get的价值!!!

于 2013-01-27T22:26:02.017 回答
1

首先,您的代码不正确,请在此处阅读有关使用 Switch 的更多信息

第二次访问来自 url 的任何变量,您可以使用全局变量 $_GET 或 $_REQUEST

你可以从这里这里阅读更多关于它们的信息

这是修复后的代码,请尝试运行它

  <?php
require("include/session_inc.php");
require("include/user_handling_inc.php");
require("include/db_inc.php");

start_Session(false, false);
$p_action=$_GET["p_action"];

switch ($p_action) {
case 'Login':
 $l_flag = verify_User($p_in_username, $p_in_password);
 if ($l_flag == "Not_Found") {
     $l_flag = "New_User";
}
 break; 

case 'Save_Profile': 
$l_flag = "Save_Profile";
    break;

case 'New_User':
$l_flag = "New_User";
    break;
case 'Create_New_User':
$l_flag = "Create_New_User";
 break;
}

switch ($l_flag) {
    case 'New_User': 
    include "include/user_new_inc.php";
    break;

case 'Save_Profile': 
    load_User_Data(" username = '$p_in_username' ", false);
    include "include/user_profile_save_inc.php";
    break;

case 'Wrong_Password': 
    echo "Wrong Pass";
    break;
case 'OK': 
    load_User_Data(" username = '$p_in_username' ", true);
    store_User_Cookie($g_userdata->user_id);
    include "include/user_profile_inc.php";
    break;
case 'Create_New_User':
$l_user_id = create_New_User ($p_in_username, $p_in_email, 'Y');
    if ($l_user_id != -1) {
        store_User_Cookie($l_user_id);
        echo "Success !! <br><br> \n";
        echo "<a href\"/index.php\"> Back to Main </a>";
     }
break;
 }
?>
于 2013-01-27T22:51:57.280 回答
0

使用$_GET获取您的参数。

有时$_REQUEST更可取,因为它同时访问获取和发布数据。

第二件事永远不要相信用户输入,所以你必须使用addlashes(); real_escape_string()函数来防止对系统的攻击。

所以代码会是这样的:

$var = addslashes($_GET['p_action']);

switch($p) {
   case 'Login':
    $l_flag = verify_User($p_in_username, $p_in_password);
    if ($l_flag == "Not_Found") {
        $l_flag = "New_User";
    }
    break;

   "OTHER CASES HERE"
}

请注意:不要为 CASE 添加 { }。在此处阅读 switch 的语法

于 2013-01-27T22:38:09.200 回答