2014-01-15 2 views
1
<input type="hidden" name="username" value="<?php echo ($_SESSION['MM_Username']) ?>" > 

나는 그것을 반향시키고 싶다. 하지만 아무리 시도해도 오류가 있습니다. 어떤 사람이 나를 도울 수 있습니까?PHP에서 echo 내에서 세션 변수를 echo하는 법

<?php echo "<input type='hidden' name='username' value='($_SESSION['MM_Username'])'"; ?> 
+2

오류가 있습니다. 실제로 오류를 표시하면 좋을 것입니다. 그러나 작은 따옴표를 사용하면 변수가 인식되지 않습니다. 이것은 큰 따옴표를 사용할 때만 발생합니다. –

+0

@Boann 왜 댓글을 쓰지? – Steve

+0

@Boann 경험이 많은 사람에게는 휴지통이지만, 우리는 한 번에 모두 거기에있었습니다. 첫 번째 스크립트가 실행되지 않았다는 것을 기억합니다 ... 누군가가 .php 확장자를 가져야한다고 지적했습니다. 누가 알았습니까 : P – Steve

답변

2
<?php echo $_SESSION['MM_Username']; ?> 

작동합니다. 그렇지 않으면 MM_Username이 비어 있습니다.

+0

안녕하세요, 나는 숨겨진 필드에 넣으려고합니다. 따라서 숨겨진 필드가 표시됩니다. 그러나 나는 그것을 반향시킬 수 없었다. – user3156220

4

session_start(); 어딘가에 스크립트 상단이 있습니까?

+0

예, 그랬습니다. 숨겨진 필드에 넣으려는 것이므로 따라서 숨겨진 필드가 표시됩니다. 그러나, 나는 그것을 반향시킬 수 없었다. – user3156220

+0

기본적인 문제 해결을해라. 페이지에 그것을 반향시킬 수 있습니까? 페이지에 값을 설정하고 해당 값이 표시되는지 확인한 다음 한 곳에서 표시되고 다른 곳에서 표시되지 않는 곳을 찾을 때까지 코드를 추적합니다. 그것이 바로 오류입니다. 기본 문제 해결, 할 수 없다면 코딩에 실패합니다. – Steve

+0

내 실수를 발견해서 고마워. btw, 나 도와 줄까? http://stackoverflow.com/questions/21134121/unset-session-does-not-work-well-php – user3156220

0

시도해보십시오. 한 가지를 기억하십시오. 코딩의 첫 번째 세션을 시작해야합니다. 그런 다음 변수 $ a를 사용하고 $ _SESSION [ 'MM_Username']; 값을 저장합니다. ?>에 $ a,

즉 $ a = $ _ SESSION [ 'MM_Username'];

지금 $ A 에코, 그 다음하지 않습니다 중 하나는 빈 항목이 있어야합니다 또는 숨겨진 필드에 결과를 표시하려는 당신이 아무것도 얻을 수 없습니다

합니다.

+0

http://stackoverflow.com/questions/21134121/unset-session-does-not-work-well -php 도움이 될까요? – user3156220

0

내 페이지를 잘 보시려면 session_start(); 그런 다음 내 HTML에는 에코 한 변수가 들어 있습니다. 도움이 되길 바랍니다.

<?php 
    if (!isset($_SESSION)) { 
     session_start(); 
    } 
    $MM_authorizedUsers = ""; 
    $MM_donotCheckaccess = "true"; 

    // *** Restrict Access To Page: Grant or deny access to this page 
    function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
     // For security, start by assuming the visitor is NOT authorized. 
     $isValid = False; 

     // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
     // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
     if (!empty($UserName)) { 
     // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
     // Parse the strings into arrays. 
     $arrUsers = Explode(",", $strUsers); 
     $arrGroups = Explode(",", $strGroups); 
     if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
     } 
     // Or, you may restrict access to only certain users based on their username. 
     if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
     } 
     if (($strUsers == "") && true) { 
      $isValid = true; 
     } 
     } 
     return $isValid; 
    } 

    $MM_restrictGoTo = "l.php"; 
    if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { 
     $MM_qsChar = "?"; 
     $MM_referrer = $_SERVER['PHP_SELF']; 
     if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; 
     if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
     $MM_referrer .= "?" . $_SERVER['QUERY_STRING']; 
     $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); 
     header("Location: ". $MM_restrictGoTo); 
     exit; 
    } 
    ?> 
    <?php 
    if (!function_exists("GetSQLValueString")) { 
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    { 
     if (PHP_VERSION < 6) { 
     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
     } 

     $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

     switch ($theType) { 
     case "text": 
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
      break;  
     case "long": 
     case "int": 
      $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
      break; 
     case "double": 
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
      break; 
     case "date": 
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
      break; 
     case "defined": 
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
      break; 
     } 
     return $theValue; 
    } 
    } 

    $editFormAction = $_SERVER['PHP_SELF']; 
    if (isset($_SERVER['QUERY_STRING'])) { 
     $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
    } 

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "new_info")) { 
     $insertSQL = sprintf("INSERT INTO new (level, test_question_no) VALUES (%s, %s)", 
          GetSQLValueString($_POST['level'], "text"), 
          GetSQLValueString($_POST['test_question'], "text")); 

     mysql_select_db($database_noundb, $noundb); 
     $Result1 = mysql_query($insertSQL, $noundb) or die(mysql_error()); 

     $insertGoTo = "variable.php"; 
     if (isset($_SERVER['QUERY_STRING'])) { 
     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; 
     $insertGoTo .= $_SERVER['QUERY_STRING']; 
     } 
     header(sprintf("Location: %s", $insertGoTo)); 
    } 

    $colname_passVar = "-1"; 
    if (isset($_SESSION['MM_Username'])) { 
     $colname_passVar = $_SESSION['MM_Username']; 
    } 
    mysql_select_db($database_noundb, $noundb); 
    $query_passVar = sprintf("SELECT * FROM counts, users WHERE users.username=%s", GetSQLValueString($colname_passVar, "text")); 
    $passVar = mysql_query($query_passVar, $noundb) or die(mysql_error()); 
    $row_passVar = mysql_fetch_assoc($passVar); 
    $totalRows_passVar = mysql_num_rows($passVar); 
    ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Select Variable Value</title> 
    </head> 

    <body> 
    <p><?php echo $row_passVar['test_question_no']; ?></p> 
    <p></p> 
    <p><a href="<?php echo $logoutAction ?>">logout</a></p> 
    <p>&nbsp;</p> 
    <p><?php echo $row_passVar['accesslevel']; ?></p> 
    <form id="new_info" name="new_info" method="POST" action="<?php echo $editFormAction; ?>"> 
     <p> 
     <input name="test_question" type="hidden" id="test_question" value="<?php echo $row_passVar['test_question_no']; ?>" /> 
     </p> 
     <p> 
     <input name="level" type="hidden" id="level" value="<?php echo $row_passVar['accesslevel']; ?>" /> 
     </p> 
     <p> 
     <input type="submit" name="submit" id="submit" value="Submit New" /> 
     </p> 
     <input type="hidden" name="MM_insert" value="new_info" /> 
    </form> 
    <p>go to <a href="index">home</a></p> 
    </body> 
    </html> 
    <?php 
    mysql_free_result($passVar); 
    ?> 
관련 문제