How can I enable displaying website into the iframe? - apache

I encountered a problem with displaying my website into the frame to show click map. An error is: "Refused to display 'https://balticland.ru/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'." But I don't have any prohibitions for that. Here is my .htaccess file.
I am using Drupal.
Can you advise me something?

X-Frame_Options is header option and it should be sent with header function before any output begins. Something like:
<?php header('X-Frame-Options: GOFORIT'); ?>
Drupal has special function for setting http headers:
https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_add_http_header/7.x
So it should be something like:
drupal_add_http_header('X-Frame-Options', 'GOFORIT');
Check out comments bellow function description.
Update:
Check out this documentation:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
It can be that you must specify external origin, like it states:
X-Frame-Options: ALLOW-FROM https://example.com/

Related

How to get request headers in instagram.com

I'm working on a small-scale instagram scraping project mainly using selenium and the python requests module. I discovered that when the Request Header changes for www.instagram.com, the text that I get from using
requests.get("https://www.instagram.com/<address>/?__a=1")
Returns the HTML code for the webpage. Instead I was expecting it to be the json text containing post details. Currently, it works fine if I change the headers manually.
How do I automatically get the request header using selenium or requests? I'm expecting to get the text labeled in the image attached:
www.instagram.com Request Header
Thank you.
import requests
response = requests.get("https://www.instagram.com/<address>/?__a=1")
print(response.status_code)
print(response.headers)
print(response.json())
As I see in the headers printed out on to console, there is a set-cookie header. If this is something that you are looking for, then you may use this line to extract only this header:
print(resp.headers['Set-Cookie'])

Rest API from PHP

I have a PayPal button which upon checkout completion redirects the user back to the homepage but in the background opens another php page which does a couple of things including updating some databases etc. However in it it I'd also like to perform a rest API request.
http://your-server/rest/createUser?username=testuser&password=testpassword
Here is the URL I need to fire and I'm not too bothered about reading the contents of this to be honest, it respond an XML file saying status OK or error messages but I don't need this... All I want to do is access the URL. This works from a browser, but when I try to use
$apicall = file_get_contents("http://your-server/rest/createUser?username=testuser&password=testpassword");
It doesn't work... Any thought ?
For file_get_contents() to work correctly any special characters have to be encoded.
$url = 'http://your-server....';
$encodedUrl = urlencode($url);
$apicall = file_get_contents($encodedUrl);
The other thing to check is that allow_url_fopen php.ini setting is set to true. (It is by default).

How to hack the HTML response from Apache HTTPD?

I need to include some HTML fragments (into the HEAD element) for each page that is handle by HTTPD. Why? I need to hack some natives javascript functions for security policy needs.
Thank you.
You could use mod_include http://httpd.apache.org/docs/2.2/mod/mod_include.html if you can edit your existing HTML files. If you don't want to do that, you will need to create a custom filter to post process the HTML. You can add the custom filter with mod_filter https://httpd.apache.org/docs/2.2/filter.html

Apache rewrite for 404: getting the requested url

On my error page that I redirect to for any 404s, I'd like to record the url that the user tried to get to.
I've tried this but it doesn't work:
ErrorDocument 404 /error/?url=%{HTTP_REFERRER}
Can anyone tell me how to do it?
Try it with %{REQUEST_URI}. I'm not certain this will work in ErrorDocument since I've never tested it, but it's worth trying.
ErrorDocument 404 /error/?url=%{REQUEST_URI}
There isn't a direct way. Nor a perfect one. But there are few workarounds with PHP.
For example, I currently use a function to create the links of each page. So I would just need to add file_exists() to the main function (few lines in a single function).
This is the function I would use to create urls:
function url ($Value)
{
// Do some stuff with the url
// [Not showed]
if (!file_exists("/internal/path/".$Value))
{
// Call a function to store the error in a database
error ("404", $Value);
// One way of handling it. Replace '/' for ' ' and search that string.
// Example: "path/to/page" would become "path to page".
$Value=str_replace("/","%20",$Value);
return "http://www.example.com/search=".$Value;
}
else
{
// If the page exists, create the normal link.
return $FullUrl;
}
}
This is my regular way of creating an urls:
<?php url('path/to/page'); ?>
I just thought about this method. It's great as it allows you to find missing pages even IF the user doesn't click on the links. Thank you for making me think about it and now I'll use it in my page (:
Another 'simpler' method (in case you do not wrap links) is that you store last couple of pages visited in $_SESSION['lastpage']; and $_SESSION['lastlastpage'];, if 404 is found then store the corresponding page from which the user tried to access the broken page. It's not a perfect solution since you have to manually find the broken link in the previous page, but at least it gives you some idea of where it is.
Disadvantage: As you can see, both solutions ONLY work with internal broken links.
It would seem there isn't a way.

Sending a custom header along with qtwebkit request

I'm doing some work with PyQt4 and QtWebKit, and in the web page request need to send a custom "Host" header along with the standard HTTP request. I'm not seeing any options for adding custom headers to the request, but this is all new to me so I hope I'm missing something. I'm looking here:
http://doc.qt.digia.com/4.6/qwebsettings.html
Any advice would be greatly appreciated.
You can set headers on the QNetworkRequest that is sent:
QNetworkRequest request;
request.setUrl(QUrl("http://qt.nokia.com"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
To use that custom request when loading a page, use the overloaded load function:
myWebView->load(request);
If you want to apply this to all requests QtWebKit makes, you can subclass QNetworkAccessManager and reimplement its createRequest() function to modify headers accordingly.