2013-10-19 2 views
-1

나는 이러한 양식공지 사항 : 정의되지 않은 인덱스 : C에서 FORM_NAME : 정의되지 않은 인덱스 : FORM_NAME

공지 사항에 문제가있는 \ XAMPP \ htdocs를 \ putline \ TEST1 \ index.php를 줄이

공지 사항 : 정의되지 않은 인덱스 : C에서 FORM_NAME : \ XAMPP \ htdocs를 \ putline \ TEST1 \ index.php를 라인 (68)

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'loginform') 
{ 
    $success_page = ''; 
    $error_page = basename(__FILE__); 
    $mysql_server = 'localhost'; 
    $mysql_username = 'root'; 
    $mysql_password = ''; 
    $mysql_database = 'putline'; 
    $mysql_table = 'user'; 
    $crypt_pass = md5($_POST['password']); 
    $found = false; 
    $fullname = ''; 
    $session_timeout = 600; 
    $db = mysql_connect($mysql_server, $mysql_username, $mysql_password); 
    if (!$db) 
    { 
     die('Failed to connect to database server!<br>'.mysql_error()); 
    } 
    mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error()); 
    $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".mysql_real_escape_string($_POST['username'])."'"; 
    $result = mysql_query($sql, $db); 
    if ($data = mysql_fetch_array($result)) 
    { 
     if ($crypt_pass == $data['password'] && $data['active'] != 0) 
     { 
     $found = true; 
     $fullname = $data['fullname']; 
     } 
    } 
    mysql_close($db); 
    if($found == false) 
    { 
     header('Location: '.$error_page); 
     exit; 
    } 
    else 
    { 
     if (session_id() == "") 
     { 
     session_start(); 
     } 
     $_SESSION['username'] = $_POST['username']; 
     $_SESSION['fullname'] = $fullname; 
     $_SESSION['expires_by'] = time() + $session_timeout; 
     $_SESSION['expires_timeout'] = $session_timeout; 
     $rememberme = isset($_POST['rememberme']) ? true : false; 
     if ($rememberme) 
     { 
     setcookie('username', $_POST['username'], time() + 3600*24*30); 
     setcookie('password', $_POST['password'], time() + 3600*24*30); 
     } 
     header('Location: '.$success_page); 
     exit; 
    } 
} 
$username = isset($_COOKIE['username']) ? $_COOKIE['username'] : ''; 
$password = isset($_COOKIE['password']) ? $_COOKIE['password'] : ''; 
?> 
<?php 
$mysql_server = 'localhost'; 
$mysql_username = 'root'; 
$mysql_password = ''; 
$mysql_database = 'putline'; 
$mysql_table = 'users'; 
$success_page = ''; 
$error_message = ""; 
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'signupform') 
{ 
    $newusername = $_POST['username']; 
    $newemail = $_POST['email']; 
    $newpassword = $_POST['password']; 
    $confirmpassword = $_POST['confirmpassword']; 
    $newfullname = $_POST['fullname']; 
    $website = $_SERVER['HTTP_HOST']; 
    $script = $_SERVER['SCRIPT_NAME']; 
    $timestamp = time(); 
    $code = md5($website.$timestamp.rand(100000, 999999)); 
    if ($newpassword != $confirmpassword) 
    { 
     $error_message = 'Password and Confirm Password are not the same!'; 
    } 
    else 
    if (!preg_match("/^[[email protected]$]{1,50}$/", $newusername)) 
    { 
     $error_message = 'Username is not valid, please check and try again!'; 
    } 
    else 
    if (!preg_match("/^[[email protected]$]{1,50}$/", $newpassword)) 
    { 
     $error_message = 'Password is not valid, please check and try again!'; 
    } 
    else 
    if (!preg_match("/^[[email protected]$.' &]{1,50}$/", $newfullname)) 
    { 
     $error_message = 'Fullname is not valid, please check and try again!'; 
    } 
    else 
    if (!preg_match("/^[email protected]+\..+$/", $newemail)) 
    { 
     $error_message = 'Email is not a valid email address. Please check and try again.'; 
    } 
    if (empty($error_message)) 
    { 
     $db = mysql_connect($mysql_server, $mysql_username, $mysql_password); 
     if (!$db) 
     { 
     die('Failed to connect to database server!<br>'.mysql_error()); 
     } 
     mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error()); 
     $sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'"; 
     $result = mysql_query($sql, $db); 
     if ($data = mysql_fetch_array($result)) 
     { 
     $error_message = 'Username already used. Please select another username.'; 
     } 
    } 
    if (empty($error_message)) 
    { 
     $crypt_pass = md5($newpassword); 
     $newusername = mysql_real_escape_string($newusername); 
     $newemail = mysql_real_escape_string($newemail); 
     $newfullname = mysql_real_escape_string($newfullname); 
     $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`, `code`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 0, '$code')"; 
     $result = mysql_query($sql, $db); 
     mysql_close($db); 
     $subject = 'Your new account'; 
     $message = 'A new account has been setup.'; 
     $message .= "\r\nUsername: "; 
     $message .= $newusername; 
     $message .= "\r\nPassword: "; 
     $message .= $newpassword; 
     $message .= "\r\n"; 
     $message .= "\r\nhttp://".$website.$script."?user=".$newusername."&code=$code"; 
     $header = "From: [email protected]"."\r\n"; 
     $header .= "Reply-To: [email protected]"."\r\n"; 
     $header .= "MIME-Version: 1.0"."\r\n"; 
     $header .= "Content-Type: text/plain; charset=utf-8"."\r\n"; 
     $header .= "Content-Transfer-Encoding: 8bit"."\r\n"; 
     $header .= "X-Mailer: PHP v".phpversion(); 
     mail($newemail, $subject, $message, $header); 
     header('Location: '.$success_page); 
     exit; 
    } 
} 
else 
if (isset($_GET['code']) && isset($_GET['user'])) 
{ 
    $db = mysql_connect($mysql_server, $mysql_username, $mysql_password); 
    if (!$db) 
    { 
     die('Failed to connect to database server!<br>'.mysql_error()); 
    } 
    mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error()); 
    $sql = "SELECT * FROM ".$mysql_table." WHERE username = '".$_GET['user']."' AND code = '".$_GET['code']."'"; 
    $result = mysql_query($sql, $db); 
    if ($data = mysql_fetch_array($result)) 
    { 
     $sql = "UPDATE `".$mysql_table."` SET `active` = 1 WHERE `username` = '".$_GET['user']."'"; 
     mysql_query($sql, $db); 
    } 
    else 
    { 
     die ('User not found!'); 
    } 
    mysql_close($db); 
    header("refresh:5;url=".basename(__FILE__)); 
    echo 'Your user account was succesfully activated. You\'ll be redirected in about 5 secs. If not, click <a href="'.basename(__FILE__).'">here</a>.'; 
    exit; 
} 
?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Untitled Page</title> 
<style type="text/css"> 
body 
{ 
    margin: 0; 
    padding: 0; 
    background-color: #FFFFFF; 
    color: #000000; 
} 
</style> 
<style type="text/css"> 
a 
{ 
    color: #0000FF; 
    text-decoration: underline; 
} 
a:visited 
{ 
    color: #800080; 
} 
a:active 
{ 
    color: #FF0000; 
} 
a:hover 
{ 
    color: #0000FF; 
    text-decoration: underline; 
} 
</style> 
<style type="text/css"> 
#loginform 
{ 
    background-color: #522D2B; 
    border: 1px #878787 solid; 
} 
#Text1 
{ 
    background-color: #6C3C39; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: center; 
} 
#Text1 div 
{ 
    text-align: center; 
} 
#Text2 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#Text2 div 
{ 
    text-align: right; 
} 
#username 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#Text3 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#Text3 div 
{ 
    text-align: right; 
} 
#password 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#Text4 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: left; 
} 
#Text4 div 
{ 
    text-align: left; 
} 
#login 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color: #000000; 
    font-family: Arial; 
    font-size: 13px; 
} 
#signupform 
{ 
    background-color: #255853; 
    border: 1px #878787 solid; 
} 
#Text5 
{ 
    background-color: #347C75; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: center; 
} 
#Text5 div 
{ 
    text-align: center; 
} 
#Text6 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#Text6 div 
{ 
    text-align: right; 
} 
#fullname 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#Text7 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#Text7 div 
{ 
    text-align: right; 
} 
#username 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#Text8 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#Text8 div 
{ 
    text-align: right; 
} 
#password 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#Text9 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#Text9 div 
{ 
    text-align: right; 
} 
#confirmpassword 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#Text10 
{ 
    background-color: transparent; 
    border: 0px #000000 solid; 
    padding: 0; 
    text-align: right; 
} 
#wb_Text10 div 
{ 
    text-align: right; 
} 
#email 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color :#A9A9A9; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#error 
{ 
    border: 0px #EEEEEE solid; 
    background-color: #255853; 
    color :#FF8C00; 
    font-family: Arial; 
    font-size: 13px; 
    text-align: left; 
    vertical-align: middle; 
} 
#signup 
{ 
    border: 1px #878787 solid; 
    background-color: #FFFFFF; 
    color: #000000; 
    font-family: Arial; 
    font-size: 13px; 
} 
</style> 
</head> 
<body> 
<div id="loginform" style="position:absolute;left:57px;top:97px;width:300px;height:175px;z-index:22;"> 
<form name="loginform" method="post" action="" enctype="text/plain" id="loginform"> 
<input type="hidden" name="form_name" value="loginform"> 
<div id="Text1" style="position:absolute;left:4px;top:4px;width:292px;height:16px;text-align:center;z-index:0;"> 
<span style="color:#FFFFFF;font-family:Arial;font-size:13px;">Log In</span></div> 
<div id="Text2" style="position:absolute;left:4px;top:32px;width:94px;height:16px;text-align:right;z-index:1;"> 
&nbsp;</div> 
<div id="Text3" style="position:absolute;left:4px;top:58px;width:94px;height:16px;text-align:right;z-index:2;"> 
&nbsp;</div> 
<div id="Text4" style="position:absolute;left:31px;top:113px;width:179px;height:16px;z-index:3;text-align:left;"> 
<span style="color:#FFFFFF;font-family:Arial;font-size:13px;">Remember me</span></div> 
<input type="checkbox" id="rememberme" name="rememberme" value="on" style="position:absolute;left:12px;top:112px;z-index:4;"> 
<input type="submit" id="login" name="login" value="Log In" style="position:absolute;left:221px;top:143px;width:76px;height:29px;z-index:5;"> 
<input type="text" id="username" style="position:absolute;left:7px;top:35px;width:279px;height:24px;line-height:24px;z-index:6;" name="username" value="<?php echo $username; ?>" placeholder="username"> 
<input type="password" id="password" style="position:absolute;left:7px;top:77px;width:279px;height:24px;line-height:24px;z-index:7;" name="password" value="<?php echo $password; ?>" placeholder="password"> 
</form> 
</div> 

<div id="signupform" style="position:absolute;left:534px;top:92px;width:313px;height:320px;z-index:24;"> 
<form name="signupform" method="post" action="<?php echo basename(__FILE__); ?>" id="signupform"> 
<input type="hidden" name="form_name" value="signupform"> 
<div id="Text5" style="position:absolute;left:4px;top:4px;width:305px;height:16px;text-align:center;z-index:8;"> 
<span style="color:#FFFFFF;font-family:Arial;font-size:13px;">Sign up for a new account</span></div> 
<div id="Text6" style="position:absolute;left:4px;top:32px;width:75px;height:16px;text-align:right;z-index:9;"> 
&nbsp;</div> 
<div id="Text7" style="position:absolute;left:4px;top:58px;width:75px;height:16px;text-align:right;z-index:10;"> 
&nbsp;</div> 
<div id="Text8" style="position:absolute;left:4px;top:84px;width:75px;height:16px;text-align:right;z-index:11;"> 
&nbsp;</div> 
<div id="Text9" style="position:absolute;left:4px;top:110px;width:75px;height:16px;text-align:right;z-index:12;"> 
&nbsp;</div> 
<div id="Text10" style="position:absolute;left:4px;top:136px;width:75px;height:16px;text-align:right;z-index:13;"> 
&nbsp;</div> 
<input type="text" id="error" style="position:absolute;left:14px;top:234px;width:150px;height:20px;line-height:20px;z-index:14;" name="error" value="<?php echo $error_message; ?>"> 
<input type="text" id="fullname" style="position:absolute;left:14px;top:27px;width:279px;height:24px;line-height:24px;z-index:15;" name="fullname" value=""> 
<input type="text" id="username" style="position:absolute;left:14px;top:66px;width:279px;height:24px;line-height:24px;z-index:16;" name="username1" value=""> 
<input type="password" id="password" style="position:absolute;left:14px;top:105px;width:279px;height:24px;line-height:24px;z-index:17;" name="password1" value=""> 
<input type="password" id="confirmpassword" style="position:absolute;left:14px;top:148px;width:279px;height:24px;line-height:24px;z-index:18;" name="confirmpassword" value=""> 
<input type="text" id="email" style="position:absolute;left:14px;top:192px;width:279px;height:24px;line-height:24px;z-index:19;" name="email" value=""> 
<input type="submit" id="signup" name="signup" value="Sgin Up" style="position:absolute;left:235px;top:289px;width:76px;height:29px;z-index:20;"> 
</form> 
</div> 

</body> 
</html> 
+0

다음 번에 질문 서식을보다 명확하게 지정하십시오. "나는 문제가있다"는 질문이 아닙니다. 또한 문제를 일으키는 줄을 분리하고 코드에서 불필요한 HTML 조각을 제거하십시오. – LSerni

+0

가능한 적은 수의 줄이면서도 문제가 계속되는 테스트 사례를 줄여보십시오. 그러면 당신과 다른 사람들이 당신의 문제를 더 잘 진단하고 해결할 수 있습니다. – emsr

답변

1

에 당신은 확인 여부를 추가 할 수 있습니다 연관 배열 인덱스 form_name이 존재/필드가 전송되었는지 여부.

if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['form_name']) && ($_POST['form_name'] == 'loginform')) 

이렇게하면주의 메시지가 표시되지 않습니다. http://us.php.net/isset

또한 프로덕션 응용 프로그램에서 보이는 PHP 오류 메시지를 해제해야합니다. 그냥 PHP로 파일에 기록하십시오. 그러나 개발 시스템에서는 그러한 메시지가 도움이됩니다.

+0

도움을 주신 것에 감사드립니다. @ MrSnrub, 다른 잘못된 로그인 양식은 작동하지 않지만 양식은 – Profile

+0

에 등록했습니다. 68 행에 예제 행과 동일한 조건을 추가해야합니다. '($ _SERVER [ 'REQUEST_METHOD'] == 'POST') && isset ($ _ POST [ 'form_name']) && ($ _POST [ 'form_name'] == 'signupform'))' 사라지다. – MrSnrub

+0

내가 그랬다. 로그인 할 때 페이지가 성공 페이지로 리다이렉트되지 않는다. "성공 페이지를 $ success_page = 'successful.php'로 푸시했다. 내가 창립 한 – Profile

관련 문제