0

I have a problem in my code and I want your help I have this site that makes an IPTV account

http://thgss.com/

This site depends on three pages before it can be downloaded On the second page "http://thgss.com/index.php?p=download2" and after entering the captcha code.

POST request is sent to 'http://thgss.com/index.php?p=download3'

With the following data : 'done=true&submit=Download+Now'

request header

POST /index.php?p=download3 HTTP/1.1
Host: thgss.com
Connection: keep-alive
Content-Length: 29
Cache-Control: max-age=0
Origin: http://thgss.com
Upgrade-Insecure-Requests: 1
DNT: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://thgss.com/index.php?p=download2
Accept-Encoding: gzip, deflate
Accept-Language: ar,en-US;q=0.9,en;q=0.8
Cookie: PHPSESSID=imbdp791tqal3fq8ifa80till1
done=true&submit=Download+Now

The m3u file link is in the reply header in location

HTTP/1.1 302 Found
Date: Tue, 18 Dec 2018 04:56:17 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.24
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
location: http://24.thgss.com:8000/get.php?username=37441545108977&password=37441545108977&type=m3u&output=mpegts
Content-Length: 2584
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

My code works well on the local server

But when you upload it to remote server show"bool(false)" error

I want you to help me check my code

my code

function getUserIP() {
    if( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
        if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')>0) {
            $addr = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
            return trim($addr[0]);
        } else {
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }
    }
    else {
        return $_SERVER['REMOTE_ADDR'];
    }
}
$ip = getUserIP() ;

$data = 'done=true&submit=Download+Now';
$headers = array(
    $data,
    'Content-Type: application/x-www-form-urlencoded',
    'Referer: http://thgss.com/index.php?p=download2',
    'X-Forwarded-For: '. $ip
);

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://thgss.com/index.php?p=download3');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
curl_setopt($curl_handle,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
var_dump($response);

1 Answer 1

1

help me get location url from reply header

You need to get info from your Curl request, and get the header from there.

Here is your code:

$ip = getUserIP() ;

$data = 'done=true&submit=Download+Now';
$headers = array(
    $data,
    'Content-Type: application/x-www-form-urlencoded',
    'Referer: http://thgss.com/index.php?p=download2',
    'X-Forwarded-For: '. $ip
);

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://thgss.com/index.php?p=download3');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
curl_setopt($curl_handle,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
var_dump($response);

Before your curl_close, add the following:

$curl_info = curl_getinfo($curl_handle);

You can then use preg_match to find your location header:

$headers = substr($response, 0, $curl_info["header_size"]);
preg_match('#Location: (.*)#', $headers, $location);

You should then find your Location header in $location, probably $location[1].

On a side note, is that the user's Username and Password you're sending in the header?

Edit:

Since the original question has been changed since I answered this, I am now editing my answer.

To help you debug any errors with the actual curl request, before curl_close you can add:

$errs = curl_error($curl_handle);

$errs will now provide you with any reasons the curl request may be failing. An example error is:

"Peer certificate cannot be authenticated with known CA certificates"

You can read more in the docs: http://php.net/manual/en/function.curl-error.php

Edit 2:

After you said you have a timeout issue,I now notice that you have used 2 seconds: curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);...

Try increasing your timeout:

curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 30);

You can also use 0 which is to wait indefinitely.

Sign up to request clarification or add additional context in comments.

8 Comments

thanks @Jonathan but whay i get bool(false) on remot server tray this link
i didnt send Username or Password just tha data in the code
You have edited your question, and you are no longer asking "help me get location url from reply header" which is what I answered. Anyway, If it works locally and not on your remote server, there's probably something different in your php configs. Have you tried using echo phpinfo(); to compare?
I've edited my answer to help you, try using $errs = curl_error($curl_handle); to get any errors from curl.
im sorry But it was running on the remote server and is no longer working and will not be anything else. The code was working without problems
|

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.