开发者

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?

The problem is that I have开发者_JS百科 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 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.


You cannot use Javascript/jQuery to access PHP header variables. 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.

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.


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. Change your example to

<?php echo "hello world" ?>

and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜