Skip to content

0325notes #22

@shiaoyi

Description

@shiaoyi

0325

使用xampp建設後端環境

打開後
General -> Start
Services -> Apache、MySQL、ProFTPD -> Start
Network -> localhost:8080->80(Over SSH) -> Enable
Volumes -> Mount
Volumes -> Explore -> lampp -> htdocs -> 創建一個資料夾(eg:yeee) -> 創建一個php檔(eg:index.php 輸入程式碼)
開瀏覽器 -> 輸入http://localhost:8080/yeee/index.php 會顯示資料

php

  • 字串連接是用點,只有數字可以用加號
<?php
    for($i = 0; $i < 10; $i++){
        echo '<li>'.$i.'</li>';
    }
?>
  • 利用isset()來檢查有無此變數
  • 利用$_GET來存到你想要的東西
<?php
$username='';
if(isset($_GET['username'])){
    $username = $_GET['username'];
}
echo 'username:'.$username.'<br>';
if($username === 'admin'){
    echo 'hello admin!';
}else{
    echo 'fail';
}
?>

url輸入http://localhost:8080/yeee/index.php?username=admin 會顯示
username:admin
hello admin!

  • php跟html可以混用,範例為利用$_POST呈現表單。也可以把表單跟php的運作分離
    url輸入http://localhost:8080/yeee/index.php 會出現帳密輸入框
    username填admin,password填admin就會登入成功並輸出username,其他則登入失敗,若頁面分離則登入失敗時會跳回index.php

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions