First, understand that you have three languages working together.
(首先,要了解您有三种语言协同工作。)
PHP: Is only run by the server and responds to requests like clicking on a link (GET) or submitting a form (POST).
(PHP:仅由服务器运行并响应请求,例如单击链接(GET)或提交表单(POST)。)
HTML & JavaScript: Is only run in someone's browser (excluding NodeJS).
(HTML和JavaScript:仅在某人的浏览器中运行(不包括NodeJS)。)
I'm assuming your file looks something like:
(我假设你的文件看起来像:)
<html>
<?php
function runMyFunction() {
echo 'I just ran a php function';
}
if (isset($_GET['hello'])) {
runMyFunction();
}
?>
Hello there!
<a href='index.php?hello=true'>Run PHP Function</a>
</html>
Because PHP only responds to requests (GET, POST, PUT, PATCH, and DELETE via $_REQUEST), this is how you have to run a PHP function even though they're in the same file.
(因为PHP只响应请求(通过$ _REQUEST获取GET,POST,PUT,PATCH和DELETE),所以即使它们在同一个文件中,也必须运行PHP函数。)
This gives you a level of security, "Should I run this script for this user or not?".(这为您提供了一定程度的安全性,“我是否应该为此用户运行此脚本?”。)
If you don't want to refresh the page, you can make a request to PHP without refreshing via a method called Asynchronous JavaScript and XML (AJAX).
(如果您不想刷新页面,可以通过名为Asynchronous JavaScript and XML(AJAX)的方法向PHP发出请求,而无需刷新。)
That is something you can look up on YouTube though.
(这是你可以在YouTube上查找的内容。)
Just search "jquery ajax"(只需搜索“jquery ajax”)
I recommend Laravel to anyone new to start off right: http://laravel.com/
(我推荐Laravel给任何新人开始吧: http ://laravel.com/)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…