함수 정의와 실행



실습 코드

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script type="text/javascript">
      function a(){
        document.write("a를 실행 ");
      }
      a();
    </script>
    <?php
      function b(){
        echo "b를 실행 ";
      }
      b();
      ?>
  </body>
</html>




함수의 입출력

입출력 기본
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script type="text/javascript">
      function a(input){
        document.write(input+1);
      }
      a(1);
    </script>
    <?php
      function b($num){
        echo $num+1;
      }
      b(5);
      ?>
  </body>
</html>


return 이용 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script type="text/javascript">
      function a(input){
      return input+1;
      }
      document.write(a(1));
    </script>
    <?php
      function b($num){
        return $num+1;
      }
      echo b(5);
      ?>
  </body>
</html>







'웹 프로그래밍' 카테고리의 다른 글

JavaScript 실습  (0) 2017.12.20
UI vs API  (0) 2017.12.19
자바스크립트, PHP로 로그인 기능 구현하기  (0) 2017.12.19
변수  (0) 2017.12.18
디버그  (0) 2017.12.18
자바스크립트로 로그인 기능 구현하기

prompt라는 것이 있다.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">

  </head>
  <body>
      <script type="text/javascript">
        prompt("비밀번호");
      </script>
  </body>
</html>

결과




사용자가 입력할 정보를 받기위한 방법은

password = propmt("비밀번호");

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
      <script type="text/javascript">
        password = prompt("비밀번호");
        document.write(password);
      </script>
  </body>
</html>


사용자가 입력한 정보를 자바스크립트가 알 수 있게 된다. 



로그인 기능 구현

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
      <script type="text/javascript">
        password = prompt("비밀번호");
        if(password == 1111) {
          document.write("안녕하세요 주인님");
        }else{
          document.write("뉘신지?");
        }
      </script>
  </body>
</html>




PHP로 로그인 기능 구현하기


위의 화면은 8-1.php 이다.

제출 버튼을 누르면

8-2.php/password=111111 창으로 간다. 

뒤에있는 password 값에 따라 나타나는 화면이 달라진다. 



구현 1

form, p, input 태그

input type = "text" text 입력

input type = "submit" => 제출 버튼
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
      <form action="8-2.php">
        <p>비밀번호를 입력해주세요.</p>
        <input type="text" name="password">
        <input type="submit">
      </form>
  </body>
</html>

8-1.php 코드
코드 해석

=> 첫 번째 input에서 name에 password 를 입력받고 그 것을 8-2.php에 보낸다.



구현 2

입력받는 것을 사용하기 위해 필요한 특수한 코드

$_GET["password"];

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <?php
      $password = $_GET["password"];
      if($password == "1111"){
        echo "주인님 환영합니다.";
      } else {
        echo "뉘신지?";
      }
     ?>
  </body>
</html>



  • HTML 줄바꿈 태그 => <br />

'웹 프로그래밍' 카테고리의 다른 글

UI vs API  (0) 2017.12.19
함수  (0) 2017.12.19
변수  (0) 2017.12.18
디버그  (0) 2017.12.18
데이터타입과 연산자  (0) 2017.12.18
JavaScript에서 변수에 저장

name  = "홍길동"

php에서 변수 저장

$name = "홍길동"



<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">

  </head>
  <body>
    <script type="text/javascript">
      name = "홍길동"
      document.write("안녕하세요 " + name);
    </script>
    <?php
      $name = "홍길동";
      echo "안녕하세요 ".$name;
    ?>
  </body>
</html>










'웹 프로그래밍' 카테고리의 다른 글

함수  (0) 2017.12.19
자바스크립트, PHP로 로그인 기능 구현하기  (0) 2017.12.19
디버그  (0) 2017.12.18
데이터타입과 연산자  (0) 2017.12.18
웹 페이지에 코드 삽입하기  (0) 2017.12.18

+ Recent posts