upload
This commit is contained in:
parent
f1107da3b5
commit
a015d57348
|
@ -8,5 +8,12 @@
|
|||
<jdbc-url>jdbc:mysql://localhost:3306/db_database11</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="db_database15@localhost" uuid="83c07ab7-6e1f-4e0c-a273-ce27fcf3a508">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost:3306/db_database15</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
|
@ -12,6 +12,7 @@
|
|||
</component>
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/../../../PHP/includes" />
|
||||
<path value="$PROJECT_DIR$/../../bin/php/php8.2.13/includes" />
|
||||
</include_path>
|
||||
</component>
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
class SportObject
|
||||
{
|
||||
public $name;
|
||||
public $height;
|
||||
public $avoirdupois;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $height
|
||||
* @param $avoirdupois
|
||||
*/
|
||||
public function __construct($name, $height, $avoirdupois)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->height = $height;
|
||||
$this->avoirdupois = $avoirdupois;
|
||||
}
|
||||
|
||||
public function bootFootBall(): string
|
||||
{
|
||||
if ($this->height < 185 and $this->avoirdupois < 85) {
|
||||
return $this->name . '符合要求';
|
||||
} else {
|
||||
return $this->name . '不符合要求';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$sport = new SportObject('明日', 185,80);
|
||||
echo $sport->bootFootBall();
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
class BookObject
|
||||
{
|
||||
const BOOK_TYPE = 'computer science';
|
||||
public string $object_name;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getObjectName(): string
|
||||
{
|
||||
return $this->object_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $object_name
|
||||
*/
|
||||
public function setObjectName(string $object_name): void
|
||||
{
|
||||
$this->object_name = $object_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$bookObject = new BookObject();
|
||||
$bookObject->setObjectName('PHP');
|
||||
echo BookObject::BOOK_TYPE . '->' . $bookObject->getObjectName();
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
class Person
|
||||
{
|
||||
public string $name;
|
||||
public float $height;
|
||||
public float $weight;
|
||||
public int $age;
|
||||
public int $sex; // 0 female 1 male
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param float $height
|
||||
* @param float $weight
|
||||
* @param int $age
|
||||
* @param int $sex
|
||||
*/
|
||||
public function __construct(string $name, float $height, float $weight, int $age, int $sex)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->height = $height;
|
||||
$this->weight = $weight;
|
||||
$this->age = $age;
|
||||
$this->sex = $sex;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
echo 'Person的析构方法被调用';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function bootFoolball(): mixed
|
||||
{
|
||||
if ($this->height < 185 && $this->weight < 85) {
|
||||
return $this->name . '符合要求';
|
||||
} else {
|
||||
return $this->name . '不符合要求';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$person = new Person(name: '明日', height: 185, weight: 80, age: 20, sex: 1);
|
||||
echo $person->bootFoolball();
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
class SportObject
|
||||
{
|
||||
public string $name;
|
||||
public int $age;
|
||||
public float $weight;
|
||||
public string $sex;
|
||||
public float $height;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $age
|
||||
* @param string $sex
|
||||
* @param float $weight
|
||||
* @param float $height
|
||||
*/
|
||||
public function __construct(string $name, int $age, string $sex, float $weight = 0.0, float $height = 0.0)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->age = $age;
|
||||
$this->weight = $weight;
|
||||
$this->sex = $sex;
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function showMe(): string
|
||||
{
|
||||
return '这是父类的showMe方法';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BeatBasketBall extends SportObject
|
||||
{
|
||||
function showMe(): string
|
||||
{
|
||||
if ($this->height > 185) {
|
||||
return $this->name . '符合要求';
|
||||
} else {
|
||||
return $this->name . '不符合要求';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WeightLifting extends SportObject
|
||||
{
|
||||
function showMe(): string
|
||||
{
|
||||
if ($this->weight < 85) {
|
||||
return $this->name . '符合要求';
|
||||
} else {
|
||||
return $this->name . '不符合要求';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$beatBasketBall = new BeatBasketBall(name: '科技', age: '18', sex: '男', height: 190);
|
||||
$weightLifting = new WeightLifting(name: '明日', age: 20, sex: '男', weight: 80, height: 185);
|
||||
echo $beatBasketBall->showMe().'<br>';
|
||||
echo $weightLifting->showMe().'<br>';
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
class SportObject2
|
||||
{
|
||||
private $object_type = 'book';
|
||||
|
||||
public function getObjectType(): string
|
||||
{
|
||||
return $this->object_type;
|
||||
}
|
||||
|
||||
public function setObjectType(string $object_type): void
|
||||
{
|
||||
$this->object_type = $object_type;
|
||||
}
|
||||
|
||||
public function __clone(): void
|
||||
{
|
||||
$this->object_type = 'computer';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$book1 = new SportObject2();
|
||||
$book2 = clone $book1;
|
||||
echo $book1->getObjectType();
|
||||
echo $book2->getObjectType();
|
||||
|
||||
class SportObject3
|
||||
{
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$book3 = new SportObject3('book');
|
||||
$book4 = $book3;
|
||||
$book5 = clone $book3;
|
||||
echo var_export($book3==$book4,true);
|
||||
echo var_export($book3===$book4,true);
|
||||
echo var_export($book3==$book5,true);
|
||||
echo var_export($book3===$book5,true);
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
//class MsubStr
|
||||
//{
|
||||
// function csubstr($str, $start, $len)
|
||||
// {
|
||||
// $strlen = $start + $len;
|
||||
// for ($i = 0; $i < $strlen; $i++) {
|
||||
// if (ord(substr($str, $i, 1)) > 0xa0) {
|
||||
// $tmpstr .= substr($str, $i, 2);
|
||||
// $i++;
|
||||
// } else {
|
||||
// $tmpstr .= substr($str, $i, 1);
|
||||
// }
|
||||
// }
|
||||
// return $tmpstr;
|
||||
// }
|
||||
//}
|
||||
// 为什么放着mb_substr不用 非要用csubstr方法?
|
||||
|
||||
$string = "关注明日科技,关注PHP从入门到精通改版!";
|
||||
$sub_string = mb_substr($string, 0, 9).'...';
|
||||
echo $sub_string;
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
class codepage_change
|
||||
{
|
||||
private string $str;
|
||||
private string $org_codepage;
|
||||
private string $tar_codepage;
|
||||
|
||||
/**
|
||||
* @param string $tar_codepage
|
||||
* @param string $org_codepage
|
||||
*/
|
||||
public function __construct(string $org_codepage, string $tar_codepage = 'UTF-8') //必须提供原编码,由于mb_detect_encoding的检测并不准确
|
||||
{
|
||||
$this->org_codepage = $org_codepage;
|
||||
$this->tar_codepage = $tar_codepage;
|
||||
}
|
||||
|
||||
public function getStr(): string
|
||||
{
|
||||
return $this->doChange($this->str);
|
||||
}
|
||||
|
||||
public function setStr(string $str): void
|
||||
{
|
||||
$this->str = $str;
|
||||
}
|
||||
|
||||
protected function doChange($str): string
|
||||
{
|
||||
return iconv($this->org_codepage, $this->tar_codepage, $str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$strr = '你好世界';
|
||||
echo $strr . '<br>';
|
||||
$strr2 = mb_convert_encoding($strr, 'gb2312', 'UTF-8');
|
||||
|
||||
$codepage_change = new codepage_change('gb2312');
|
||||
$codepage_change->setStr($strr2);
|
||||
echo $codepage_change->getStr();
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
class ProcessMsg
|
||||
{
|
||||
/**
|
||||
* @param $msg
|
||||
* @return void
|
||||
*/
|
||||
public function simpleMsg($msg): void
|
||||
{
|
||||
echo $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $msg
|
||||
* @param $url
|
||||
* @return void
|
||||
*/
|
||||
public function jumpMsg($msg, $url = null): void
|
||||
{
|
||||
if ($url == null) {
|
||||
echo '<script>alert("' . $msg . '");location.reload()</script>';
|
||||
} else {
|
||||
echo '<script>alert("' . $msg . '");location.href="' . $url . '"</script>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $msg
|
||||
* @param $time
|
||||
* @param $url
|
||||
* @return void
|
||||
*/
|
||||
public function jumpMsgPending($msg, $time, $url = null): void
|
||||
{
|
||||
if ($url == null) {
|
||||
$hr = $_SERVER['HTTP_REFERER'];
|
||||
echo $msg . '<br>';
|
||||
echo '页面将于' . $time . '秒后跳转。如果没有跳转,请点击这里<a href="' . $hr . '">返回</a>';
|
||||
echo '<meta http-equiv="refresh" content="' . $time . ';url=' . $hr . '"/>';
|
||||
} else {
|
||||
echo $msg . '<br>';
|
||||
echo '页面将于' . $time . '秒后跳转。如果没有跳转,请点击这里<a href="' . $url . '">返回</a>';
|
||||
echo '<meta http-equiv="Refresh" content="' . $time . ';url=' . $url . '">';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pm = new ProcessMsg();
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>登录</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="14.work2.login_v.php">
|
||||
<label for="username1">用户名:</label>
|
||||
<input type="text" name="username" id="username1">
|
||||
<input type="submit" name="submit" id="submit1" value="submit">
|
||||
</form>
|
||||
</body>
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
include_once '14.work2.fun.php';
|
||||
$pm = new ProcessMsg();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['submit'])) {
|
||||
$username = $_POST['username'];
|
||||
if (empty($username)) {
|
||||
echo 'I\'m here';
|
||||
|
||||
$pm->jumpMsg('username is empty','14.work2.login.php');
|
||||
} else {
|
||||
if ($username == 'admin') {
|
||||
$pm->jumpMsgPending('Login success', 3,'14.work2.main.php');
|
||||
} else {
|
||||
$pm->jumpMsg('Username is incorrect','14.work2.login.php');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$pm->jumpMsg('Not allow GET requests', '14.work2.login.php');
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>test1</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
include_once '14.work2.fun.php';
|
||||
$pm = new ProcessMsg();
|
||||
$pm->simpleMsg('欢迎光临');
|
||||
?>
|
||||
</body>
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
$raw_str = 'hello world';
|
||||
echo '加密前'.$raw_str.'<br>';
|
||||
$salt = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 22);
|
||||
$enc_str = crypt($raw_str,$salt);
|
||||
echo '加密后'.$enc_str.'<br>';
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
class UserManage
|
||||
{
|
||||
private ?mysqli $mysqli;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->mysqli = $this->dbConnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mysqli|void
|
||||
*/
|
||||
private function dbConnect()
|
||||
{
|
||||
$mysqli = mysqli_connect('localhost', 'root', 'chenx221') or die('数据库连接错误' . mysqli_connect_error());
|
||||
mysqli_select_db($mysqli, 'db_database15') or die('数据库访问失败,请检查数据库db_database15是否存在');
|
||||
mysqli_set_charset($mysqli, 'utf8mb4');
|
||||
return $mysqli;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
mysqli_close($this->mysqli);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @return void
|
||||
*/
|
||||
public function registerUser($username, $password): void
|
||||
{
|
||||
$stmt = $this->mysqli->prepare("select username from tb_user where username = ?");
|
||||
$stmt->bind_param("s", $username);
|
||||
$stmt->execute();
|
||||
$user = null;
|
||||
$stmt->bind_result($user);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
if ($user != null) {
|
||||
echo '<script>alert("username already exists")</script>';
|
||||
} else {
|
||||
$enc_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $this->mysqli->prepare("insert into tb_user (username, password) values (?, ?)");
|
||||
$stmt->bind_param("ss", $username, $enc_password);
|
||||
$stmt->execute();
|
||||
$result = $stmt->affected_rows;
|
||||
$stmt->close();
|
||||
if ($result == 1) {
|
||||
echo '<script>alert("register success")</script>';
|
||||
} else {
|
||||
echo '<script>alert("register failed")</script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @return void
|
||||
*/
|
||||
public function loginUser($username, $password): void
|
||||
{
|
||||
$enc_password = null;
|
||||
$stmt = $this->mysqli->prepare("select password from tb_user where username = ?");
|
||||
$stmt->bind_param("s", $username);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($enc_password);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
if ($enc_password != null) {
|
||||
if (password_verify($password, $enc_password)) {
|
||||
echo '<script>alert("login success")</script>';
|
||||
} else {
|
||||
echo '<script>alert("Password is wrong")</script>';
|
||||
}
|
||||
} else {
|
||||
echo '<script>alert("username not exists")</script>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
require_once '15.test2.lib.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['submit'])) {
|
||||
$userManage = new UserManage();
|
||||
|
||||
if ($_POST['function_selector'] == 'register') {
|
||||
if (!empty($_POST['username']) && !empty($_POST['password'])) {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
$userManage->registerUser($username, $password);
|
||||
} else {
|
||||
echo '<script>alert("username or password is empty")</script>';
|
||||
}
|
||||
} else {
|
||||
if (!empty($_POST['username']) && !empty($_POST['password'])) {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
$userManage->loginUser($username, $password);
|
||||
} else {
|
||||
echo '<script>alert("username or password is empty")</script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>test2</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="">
|
||||
<label for="username1">username</label>
|
||||
<input type="text" name="username" placeholder="username" id="username1">
|
||||
<br>
|
||||
<label for="password1">password</label>
|
||||
<input type="password" name="password" placeholder="password" id="password1">
|
||||
<br>
|
||||
<label for="fselector1">register</label>
|
||||
<input type="radio" name="function_selector" id="fselector1" value="register">
|
||||
<label for="fselector2">login</label>
|
||||
<input type="radio" name="function_selector" id="fselector2" value="login" checked>
|
||||
<br>
|
||||
<input type="submit" name="submit" value="submit">
|
||||
</form>
|
||||
</body>
|
Loading…
Reference in New Issue