1

Here's the quick and dirty: I've written a bunch of HTML, CSS, and Javascript (with jQuery) for a site. I've got everything hosted on an Apache server, so I believe it's possible for me to add a bit of PHP script to the site, but I'm not sure as to how as I do not know PHP.

The bit of script I'd like to add is this, which should supposedly allow me to open sites like Facebook or YouTube in an iframe:

<?php
header('X-Frame-Options: GOFORIT'); 
?>

(I got this bit of code from here).

So how do I implement it? I apologize for such a beginner problem, it's just that I haven't gotten around to learning PHP yet. If possible, try to keep your answers simple, as, again, I'm new at this. Thanks for the help!

1
  • I didn't get your point as I think you have JS scripts and want to add it to the server but the server is PHP and you don't know as you want the header/application to open as X-Fram-Options
    – Vineet1982
    Commented Mar 2, 2013 at 16:02

3 Answers 3

3

Since you are using Apache Web Server you can use the Header directive. Although this resource is dated, here is an explanation using X-Frame-Options with Apache header directive

#Add to httpd.conf configuration file.
Header always append X-Frame-Options SAMEORIGIN
2
  • So, to be clear, I don't need to install anything? I just have to add that line to the end of my httpd file?
    – Ian Zane
    Commented Mar 2, 2013 at 17:15
  • 1
    Apache docs point out, "The directives provided by mod_headers can occur almost anywhere within the server configuration, ...". So appending to end of httpd should be fine. You can also make sure mod_headers.so is not disabled, append the Header directive and restart apache. Another useful and related resource: Add HTTP Headers in Apache Response
    – medokr
    Commented Mar 2, 2013 at 17:55
1

Some people have disscussed this same topic here perhaps it helps

1

Assuming you have installed mod_php into apache (and restarted apache after the install), from my experience, you need to have the PHP code within a document in your web server directory that has an extension of .php (a PHP file). To add the PHP, you would simply add that bit of code to the top of your document, like the following:

<?php
header('X-Frame-Options: GOFORIT'); 
?>
<html>
...
</html>

If you do that and it still doesn't work, this may help (should work with ubuntu's apache2 package):

sudo apt-get install php5 libapache2-mod-php5
sudo service apache2 restart
cd /var/www
sudo mv index.html index.php

This assumes your webserver directory is /var/www, and that your account can't write there. This also assumes that your HTML document is index.html (replace that with whatever your document is).

After doing this, you should be able to access localhost and your PHP script should execute. If you want to test it without using a frame the facebook or youtube (or if that particular bit of PHP code doesn't work), you can use this PHP code:

<?php
phpinfo();
?>

This will display a lot of information about your PHP installation, which will be printed right to the browser (so you will see if it works).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.