简体   繁体   English

使用 Javascript/jQuery 访问 PHP header 变量

[英]Access PHP header variables using Javascript/jQuery

this is probably a very stupid question, but here it goes anyways... would it be possible to somehow access PHP header variables like the $_POST variable for instance, from within a HTML page, using Javascript/jQuery?这可能是一个非常愚蠢的问题,但无论如何......是否有可能以某种方式访问 PHP header 变量,例如$_POST变量,从 HTML 页面中使用 Javascript/Javascript?

The problem is that I have a site that uses a PHP CMS but the templating system uses .html files and pre defined tags, so basically I would like to be able to use PHP on the HTML template files somehow. The problem is that I have a site that uses a PHP CMS but the templating system uses .html files and pre defined tags, so basically I would like to be able to use PHP on the HTML template files somehow.

I have tried all of the methods shown on this site, but my PHP seems to be showing up in the source of the page as an HTML comment, like so,我已经尝试了站点上显示的所有方法,但是我的 PHP 似乎在页面源中显示为 HTML 评论,就像这样,

<!--php echo "hello world" -->

any idea how I can get around this problem?知道如何解决这个问题吗?

Thanx in advance!提前谢谢!

If your HTML pages are not being interpreted by the PHP interpreter (indicated by the PHP statements in your source), you cannot access any PHP header variables. If your HTML pages are not being interpreted by the PHP interpreter (indicated by the PHP statements in your source), you cannot access any PHP header variables.

You cannot use Javascript/jQuery to access PHP header variables.您不能使用 Javascript/jQuery 访问 PHP header 变量。 The reason behind it is because this kind of information is only available at the server side of things since they're related to HTTP and javascript is a client side language that knows nothing about the server.其背后的原因是因为此类信息仅在服务器端可用,因为它们与 HTTP 和 javascript 是一种对服务器一无所知的客户端语言。

What you could do is use PHP to save the HTTP header's information in a variable and do whatever you want to do with it.你可以做的是使用 PHP 将 HTTP 标头的信息保存在一个变量中,然后做任何你想做的事情。

If you let PHP process your HTML files by changing .htaccess accordingly, the most likely thing that goes wrong is that you don't use proper PHP tags.如果您让 PHP 通过相应地更改.htaccess来处理您的 HTML 文件,那么最有可能出错的是您没有使用正确的 Z2237138 标记22084A。 Change your example to将您的示例更改为

<?php echo "hello world" ?>

and see what happens.看看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM