0

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 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!

4
  • 1
    Could you use AJAX to call another PHP script? Commented May 5, 2011 at 12:07
  • Which CMS are you using? Commented May 5, 2011 at 12:15
  • @Mild: Why would one need to rely on JavaScript if one merely wants to insert a POST parameter into the markup? Moreover, the parameter will not be available anymore when the page loading is finished, so you'll have to work around that. BTW, don't forget to protect against XSS attacks. Commented May 5, 2011 at 12:17
  • @Nick: It is actually a shopping cart with built in CMS functionality, so I can understand them removing PHP from the templating system. Commented May 5, 2011 at 12:27

3 Answers 3

0

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.

0

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.

0

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.

3
  • My PHP tags are fine in the template file, but then when I load the page, it shows up as an HTML comment, so it might be getting parsed along the way? Commented May 5, 2011 at 12:07
  • It's a Interspire product, I'm thinking that is probably it, it's understandable, but very very limiting. -_- Commented May 5, 2011 at 12:12
  • @user I don't know those, but I can't think of anything else. Commented May 5, 2011 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.