handler_login.php 파일에서 모든 변수에 액세스 할 수있게하고 싶습니다. handler_question.php 파일에서 include
을 사용하고 있습니다. handler_question.php은 다음 형식의 데이터를 처리합니다.PHP include 명령을 이해하려면 -command
내 form_question.php
<form method="post" action="handler-question.php">
<p>Title:
<input name="question_title" type="text" cols="92" />
</p>
<p>Question:
<div id="wmd-container" class="resizable-textarea">
<textarea id="input" class="textarea" tabindex="101" rows="15" cols="92" name="question_body" /></textarea>
</div>
</p>
<p>Tags:
<input name="tags" type="text" cols="92" />
</p>
<input type="submit" value="OK" />
</form>
다음 파일을 마지막 파일이
내 handler_login.php
<?php
// independent variables
$dbHost = "localhost";
$dbPort = 5432;
$dbName = "masi";
$dbUser = "masi";
$dbPassword = "123456";
$conn = "host=$dbHost port=$dbPort dbname=$dbName user=$dbUser password=$dbPassword";
// you can store the username and password to $_SESSION variable
$dbconn = pg_connect($conn);
if(!$dbconn) {
exit;
}
$sql = "SELECT username, passhash_md5, email
FROM users
WHERE username = '{$_POST['username']}'
AND email = '{$_POST['email']}'
AND passhash_md5 = '{$_POST['password']}';";
$result = pg_query($dbconn, $sql);
if(!$result) {
exit;
}
$username = $_POST['username'];
$passhash_md5 = md5($_POST['password']);
// COOKIE setting /*{{{*/
/* $cookie may look like this:
variables
$username = "username"
$passhash_md5 = "password-in-md5"
before md5:
"usernamepasshash_md5"
after md5:
"a08d367f31feb0eb6fb51123b4cd3cb7"
*/
$login_cookie = md5(
$username .
$passhash_md5
);
$sql3 = "SELECT passhash_md5
FROM users
WHERE username=$_POST['username'];";
$password_data_original = pg_query($dbconn, $sql3);
while ($row = pg_fetch_row($data)) {
$password_original = $row[0];
}
$login_cookie_original = md5(
$username .
$password_original
);
// Check for the Cookie
if (isset($_COOKIE['login']))
{
// Check if the Login Form is the same as the cookie
if ($login_cookie_original == $login_cookie)
{
header("Location: index.php");
die("logged in");
}
header("Location: index.php");
die("wrong username/password");
}
// If no cookie, try logging them in
else
{
//Get the Data
// we do not want SQL injection so we use pg_escape_string
$sql2 = sprintf("SELECT * from users
WHERE passhash_md5='%s',
pg_escape_string($login_cookie));
$raw_user_list = pg_query($dbconn, $sql2);
if ($user = pg_fetch_row($row_user_list)) {
setcookie ("login", $login_cookie);
header("Location: index.php");
die("logged in");
} else {
header("Location: index.php");
die("wrong username/password");
}
}
pg_close($dbconn);
?>
그리고 마지막으로 내 handler_question.php를 포함하는 것입니다 문제가 발생하는 곳
<?php
include 'handler-login.php'; // This is the problem
$question_body = '{$_POST['question_body']}' // I get an error right from the beginning
$question_title = '{$_POST['question_title']}'
$sql_questions_question_id = "SELECT question_id FROM users
WHERE username = $username;"
// $username comes from handler_login.php
$questions_question_id = pg_query($dbconn, $sql_questions_question_id);
// to get tags to an array
$tags = '{$_POST['question_tags']}';
$tags_trimmed = trim($tags);
$tags_array = explode(",", $tags_trimmed);
// to save the cells in the array to db
$sql_tags_insert = "INSERT INTO tags (tag, questions_question_id)
VALUES (for ($i = 0; $i < count($tags_array); $i++)"
$sql = "SELECT username, passhash_md5, email
FROM users
WHERE username = '{$_POST['username']}'
AND email = '{$_POST['email']}'
AND passhash_md5 = '{$_POST['password']}';";
$result = pg_query($dbconn, $sql);
if(!$result) {
exit;
}
$username = $_POST['username'];
$passhash_md5 = md5($_POST['password']);
pg_close($dbconn);
?>
handler_login.php의 모든 변수를 handler_question.php로 어떻게 액세스 할 수 있습니까?
@Masi : "처음부터 오류가 있습니다."- 오류가 무엇입니까? – RichieHindle
제발, 당신의 대답에 의견을 참조하십시오. –
답변 해 주셔서 감사합니다. –