I want to show my problem and I hope to find a solution I have this website to generate IPTV accounts http://iptv.alkaicerteams.com/iptv/index.php This site contains several passwords that are randomly exchanged by the short link above The password is confirmed by the short link
The site then sends the password to the following link to generate an account http://iptv.alkaicerteams.com/iptv/post.php And it has asked the head
POST /iptv/post.php HTTP/1.1
Host: iptv.alkaicerteams.com
Connection: keep-alive
Content-Length: 21
Accept: */*
Origin: http://iptv.alkaicerteams.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
DNT: 1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://iptv.alkaicerteams.com/iptv/index.php
Accept-Encoding: gzip, deflate
Accept-Language: ar,en-US;q=0.9,en;q=0.8
Cookie: PHPSESSID=q4l3hp1h2cvm1amvaq69uund96
user=1120135520184221
The reply will be
HTTP/1.1 200 OK
Date: Sat, 15 Dec 2018 03:22:47 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.26
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
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 89
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
{"status":"success","username":"Kaicer_J7klnKAP","password":"4qu17iCzKC"}
You have typed a code that identifies the short link and identifies the password http://iptv.alkaicerteams.com/iptv/index.php And then send the data to http://iptv.alkaicerteams.com/iptv/post.php But the response comes
POST /iptv/post.php HTTP/1.0
Host: iptv.alkaicerteams.com
Connection: close
Content-Length: 21
Content-type: application/x-www-form-urlencoded
user=2224248965317031
HTTP/1.1 200 OK
Date: Sat, 15 Dec 2018 03:28:44 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.26
Set-Cookie: PHPSESSID=9h8hvbfriusnhn7lcf3ns00g85; path=/
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
Content-Length: 38
Connection: close
Content-Type: application/json; charset=UTF-8
{"status":"error","message":"invalid"}
What is the problem with my code
<?php
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://iptv.alkaicerteams.com/iptv/index.php');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$query = curl_exec($curl_handle);
curl_close($curl_handle);
$lines = explode("
", $query);
$shotline= $lines[257];
$shotline = preg_replace('/\s+/', '', $shotline);
preg_match('/(http:\/\/[^\s]+)/', $shotline, $text);
$solit_shor_url =($text[0]);
$end_short_url = substr($solit_shor_url, 0, 19);
$pass ='';
if ($end_short_url=='http://gsul.me/e4uM') {
$pass ='user=2224248965317031';
} else if ($end_short_url=='http://gsul.me/e4uT') {
$pass ='user=1120135520184221';
}
else if ($end_short_url=='http://gsul.me/e4uX') {
$pass ='user=9999600017456111';
}
else if ($end_short_url=='http://gsul.me/e4v0') {
$pass ='user=9441513141365431';
}
else if ($end_short_url=='http://gsul.me/e4un') {
$pass ='user=3354872122101111';
}
else if ($end_short_url=='http://gsul.me/e4uw') {
$pass ='user=798460044567891';
}
else if ($end_short_url=='http://gsul.me/e4us') {
$pass ='user=7513000478963541';
}
else if ($end_short_url=='http://gsul.me/e4vc') {
$pass ='user=4242421596324581';
}
else if ($end_short_url=='http://gsul.me/e4uo') {
$pass ='user=7531596542584301';
}
else if ($end_short_url=='http://gsul.me/e4uG') {
$pass ='user=5303306289156271';
}
else {
$pass ='erorr';
}
//echo 'url: '.$end_short_url ;
//echo 'pass: '.$pass ;
$url = 'http://iptv.alkaicerteams.com/iptv/post.php';
//$ID = $_GET['id'];
//pass = http://iptv.alkaicerteams.com/iptv/
$data = $pass ;
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded
",
"Origin: http://iptv.alkaicerteams.com",
'method' => 'POST',
'content' => $data,
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
//$XX= $json_a['username'];
echo $result ;
The problem is that the PHP backend on the second request to /iptv/post.php
expects the user to be authenticated, i.e. him to send auth cookie he obtained on the first request. In order to do that you can use CURLOPT_COOKIEJAR
and CURLOPT_COOKIEFILE
cURL options and save/retrieve cookies from a temporary file placed in /tmp
folder.
You can also update your code to not parse the HTML output and remove hardcoded 257
line. Even though it's better to address the elements of an HTML tree using DOM, since you need just the short URL you can use PCRE here.
Also, please rewrite your if/elseif/else code into switch/case if there is no other option to put this all into a hashtable to a config or a database.
So this code works fine:
$cookies = tempnam('/tmp','cookie.txt');
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://iptv.alkaicerteams.com/iptv/index.php');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $cookies);
$response = curl_exec($curl_handle);
$matches = [];
preg_match('/\'(http:\/\/gsul\.me\/[a-zA-Z0-9]*?)\'/', $response, $matches);
curl_close($curl_handle);
$end_short_url = $matches[1];
switch($end_short_url) {
case 'http://gsul.me/e4uM':
$pass = 'user=2224248965317031';
break;
case 'http://gsul.me/e4uT':
$pass = 'user=1120135520184221';
break;
case 'http://gsul.me/e4uX':
$pass = 'user=9999600017456111';
break;
case 'http://gsul.me/e4v0':
$pass = 'user=9441513141365431';
break;
case 'http://gsul.me/e4un':
$pass = 'user=3354872122101111';
break;
case 'http://gsul.me/e4uw':
$pass = 'user=798460044567891';
break;
case 'http://gsul.me/e4us':
$pass = 'user=7513000478963541';
break;
case 'http://gsul.me/e4vc':
$pass = 'user=4242421596324581';
break;
case 'http://gsul.me/e4uo':
$pass = 'user=7531596542584301';
break;
case 'http://gsul.me/e4uG':
$pass = 'user=5303306289156271';
break;
default:
$pass ='erorr';
break;
}
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://iptv.alkaicerteams.com/iptv/post.php');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $pass);
$response = curl_exec($curl_handle);
curl_close($curl_handle);
var_dump($response);