R
R
RaininoYT2020-05-29 21:35:36
PHP
RaininoYT, 2020-05-29 21:35:36

How to transfer REFERER PНP?

Hello!
I have a PHP script that accesses a page on the server, access to which is configured through a referer.
How can I specify in this script the referer of the site from which it accesses the server? And then, the server does not recognize its referrer by default.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AUser0, 2020-05-29
@AUser0

It all depends on how the script actually addresses.
If curl_exec() is used, the referer is specified in curl_setopt($ch, CURLOPT_REFERER, $referer_string).
If the built-in PHP wrapper of the file_get_contents() type is used, then through stream_context_create().
And if everything is done kosherly via fsockopen() - you yourself form the HTTP request...

N
nokimaro, 2020-05-30
@nokimaro

https://www.php.net/manual/en/context.http.php

<?php
$context = stream_context_create([
    "http" => [
        "method" => "GET",
        "header" => [
            "Referer: XXXXXXXXX"
        ],
    ]
]);

$result = file_get_contents('http://www.ru/', false, $context);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question