在< a>中调用PHP函数标签,锚标签 [英] Calling a PHP function within an <a > tag, anchor tag

查看:79
本文介绍了在< a>中调用PHP函数标签,锚标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在锚标记中调用PHP函数?我有一个名为 logout();



的PHP函数现在我想要类似这样的东西。

 < a href =logout(); >退出< / A> 

我知道Javascript有效,但使用PHP函数的最佳方法是什么?

解决方案

不; PHP是一种服务器端脚本语言,因此它无法像HTML那样访问HTML。 JavaScript可以做到这一点,因为它是客户端脚本语言



因为PHP是一种服务器端语言,所以必须从浏览器(客户端)向服务器发送一条消息(以HTTP请求的形式)包括您的PHP函数 logout



您有几个选项...



选项1



按照超链接执行 logout()函数的脚本...



HTML

 < a href =theLogOutScript .PHP>退出< / A> 

PHP

 <?php 
// ...
logout();
// ...
?>



选项2



执行 logout()函数的脚本...



HTML

 < form method =POSTaction =theLogOutScript.php> 
< input type =submitvalue =注销/>
< / form>



选项3



使用 XMLHttpRequest / AJAX请求与服务器进行通信。 (没有提供示例代码)

Is it possible to call a PHP function within an anchor tag. I have a PHP function called logout();

Now I want something similar to this.

<a href="logout();" >Logout</a>

I know with Javascript this works but what is the best approach using PHP function?

解决方案

No; PHP is a server side scripting language, so it is inaccessible to the HTML like this. JavaScript can do this, as it is a client-side scripting language.

Since PHP is a server side language, a message (in the form of an HTTP request) must be sent to the server from the browser (the client) for any PHP to be executed - including your PHP function logout.

You have a few options...

Option 1

Follow the hyperlink to a script which executes the logout() function...

HTML

<a href="theLogOutScript.php">Logout</a>

PHP

<?php
   // ...
   logout();
   // ...
?>

Option 2

Submit a form to a script which executes the logout() function...

HTML

<form method="POST" action="theLogOutScript.php">
    <input type="submit" value="Logout" />
</form>

Option 3

Use an XMLHttpRequest/AJAX request to communicate with the server. (no sample code provided)

这篇关于在&lt; a&gt;中调用PHP函数标签,锚标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆