php에서 버튼을 눌렀을 때 변수와 함께 다른 페이지를 호출 하는 방법

ant01의 이미지

php에서 버튼을 눌렀을 때 사용 중 이던 변수와 함께 다른 페이지를 호출 하는 방법좀 알려 주시면 감사하겠습니다.

사용 중 이던 변수라 함은 입력받은 변수가 아니고 페이지 내부에서 사용하던 변수입니다.

noblepylon의 이미지

<form action="index.php?q=verify" method="post">
    ...
    <input type="hidden" name="변수명" value="$페이지_내부_변수명" />
    <button type="submit">전송</button>
</form>

submit 버튼을 누를때 같이 보낼수 있죠. 물론 소스보기하면 다 나옵니다.

소스에 나타나는게 싫다면 세션 변수를 만들수도 있습니다:

<?php
session_start();
...
$_SESSION["변수명"] = $페이지_내부_변수명;
?>

하지만 이것도 브라우저 설정에서 다 보입니다.
애초에 비밀번호같이 보이면 안되는 정보는 페이지에서 페이지로 전달(?)하면 위험합니다.
데이터베이스에 저장해놓고 그때그때 빼서 쓰는게 안전하죠.

----------------------------------------------------
이상 초보의 답변입니다. 틀린점이 있으면 지적해주세요

---
“내게 능력주시는 자 안에서 내가 모든 것을 할 수 있느니라.”(빌립보서 4:13)

ant01의 이미지

정말 감사합니다. 잘 될 것 같군요.
password에 쓸려는 것은 아니고 달력에 버튼을 달아 앞 뒤 달로 넘기는 기능을 추가하고 싶어서 그랬습니다.

noblepylon의 이미지

form태그를 쓰기가 좀 그렇다면 그냥 url에다가 같이 달아서 보내는 방법도 있습니다:

<div data-role="header" data-theme="f">
    &lt;a href="?q=calendar&month=<?php echo $prev; ?>"&gt;이전 달&lt;/a&gt;
    <p><strong><?php echo $this->year . '년' . $this->month . '월'; ?></strong></p>
    &lt;a href="?q=calendar&month=<?php echo $next; ?>"&gt;다음 달&lt;/a&gt;
</div>

물론 이런 경우엔 받는 쪽에서 필터링을 잘 해줘야겠죠. (악의를 가진 사람이 url에 month=-1.5를 넣는다면?)
<?php
...
// month 변수를 GET으로 받아옴
// 특정형식에 맞지 않으면 예외처리
// 바른 형식: yyyymm   예: 201205
    if(!verify_int($_GET["month"], 6)) 
        throw new Exception("잘못된 요청입니다.");
    $this->year = intval(substr($_GET["month"], 0, 4));
    $this->month = intval(substr($_GET["month"], 4, 2));
    if(empty($this->year) || empty($this->month) || !checkdate($this->month, 1, $this->year))
        throw new Exception("잘못된 요청입니다.");
    $this->wday = intval(date("w", strtotime($this->year . "-" . $this->month . "-1")));
...
...
// 숫자가 특정한 자리수인지 판별
function verify_int($str, $length = 0) {
    if(!$length)
        return preg_match("/^[0-9]+$/", $str);
    else
        return preg_match("/^[0-9]{" . $length . "}$/", $str);
}
?>

---
“내게 능력주시는 자 안에서 내가 모든 것을 할 수 있느니라.”(빌립보서 4:13)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.