Hey I've a problem with my code.
It works fine for the first 10 name, but then "file_get_contents" return just empty strings
Is this a timeout problem? or has it a other reason?
And how can i fix this?
my Code:
<?php
$member;
mysql_connect("localhost","**********","********");
mysql_select_db('bf3_ezstats');
$sql = mysql_query('SELECT id, name FROM ez2bf3_player ORDER BY id ASC');
while($row = mysql_fetch_assoc($sql)){
$member[$row['id']] = $row['name'];
}
mysql_close();
print_r($member);
foreach ($member as $ip => $player){
ini_set('default_socket_timeout', 120);
$SC = file_get_contents('http://battlelog.battlefield.com/bf3/user/'.$player);
$SC = split('<surf:container id="profile-gamereport-previews">',$SC);
$SC = split('</surf:container>',$SC[1])[0];
$IPs = array(0=>$player);
while(strpos($SC,'href') !== false){
$start = strpos($SC,"href");
$end = strpos($SC,'"',$start+6);
$IP= substr($SC,$start,$end-$start);
$IPs[] = "http://battlelog.battlefield.com".str_replace('href="',"",$IP);
$SC = substr($SC,$end,strlen($SC)-1);
}
print_r($IPs);
}
?>
file_get_contents() on external URIs is just a huge security issue. This method could lead to many errors, probably including yours.
If you need to work on external servers, through HTTP, I strongly recommand the use of cURL (http://php.net/manual/fr/book.curl.php). You'll find it more handy, I think, and you may save yourself a lot of trouble.
Related
Sorry if I'm not good at formulating questions or if this isn't a good question, but I've been trying for days and getting no progress on this and I'm ready to effing cry. Please, please help.
So this PHP file:
<?php
header("Content-Type: application/json; charset=UTF-8");
$obj = json_decode($_GET["x"], true);
$conn = new mysqli("localhost", "user", "password", "database");
$i = 1;
$message = array();
while ($i < 31){
$query = $conn->prepare("SELECT dag, maand, jaar, timeslot FROM boeker WHERE dag = $i AND maand = ? AND jaar = ?");
$query->bind_param('ii', $obj["monthQ"], $obj["yearQ"]);
$query->execute();
$result = $query->get_result();
$outp = $result->fetch_all(MYSQLI_ASSOC);
$message = array();
if(empty($result)){
//available
} else if ($result["timeslot"] == null){
array_push($message, "occupied", $i);
} else {
array_push($message, $result["timeslot"], $i);
}
$i++;
}
$package = json_encode($message);
echo $package;
?>
is getting this request:
https://url/file.php?x='{"monthQ":10,"yearQ":2021}'
and the reply is an empty Response Payload, which throws an error, because it can't be JSON.parsed
I would think that $message, even when the array stays empty, would make $package a simple [], which should parse...
Is something wrong with my PHP?
Thanks for any help!
You need to remove the single quotes around the json string in your url. If you have no control over constructing that url, you can just run:
$obj = json_decode(trim($_GET['x'],"'"), true);
I've tested that, and it works.
If you do have control over constructing that url, I recommend that you remove the single quotes AND urlencode the json block.
Leaving breadcrumbs after solving a similar problem here. My php.ini file had a max_post_size set to 2K and I was sending a POST request with size >2K. PHP decided to sweep the problem under the rug and proceed with the request with an empty body.
The code I am using is:
$url = "example.com";
$code = file_get_contents("http://www.".$url);
if (!$code) {
$code = file_get_contents("https://www.".$url);
}
I don't know whether each URL starts with http or https. I have 1,000 URLs saved in my database. Any suggestions?
This answer is somewhat relevant. Given that your database is rather incomplete in that the URLs aren't fully qualified, I would be inclined to write a short routine to update the database for future use.
<?php
$url = 'example.com';
$variations[] = 'http://'.$url;
$variations[] = 'https://'.$url;
$variations[] = 'http://www.'.$url;
$variations[] = 'https://www'.$url;
foreach($variations as $v){
// Check variation with function from answer linked above
if(urlOK($v)){
// code to update database row
// or if you don't want to do that
$code = file_get_contents($v);
}
}
Hi there I'm trying to write a .php file using this code, server replying this error : syntax error, unexpected '0' (T_LNUMBER) in
I wanna know how can I write integer in php file as you can see
$status1 = \''0'\';
This code having problem, anybody please tell me what to do.
<?php
if(isset($_POST['user1'])){
$data = urldecode('%3C').'?php
$user1 = \''.$_POST['user1'].'\';
$pass1 = \''.$_POST['pass1'].'\';
$status1 = \''0'\';
$user2 = \''.$_POST['user2'].'\';
$pass2 = \''.$_POST['pass2'].'\';
$status2 = \''0'\';
$user3 = \''.$_POST['user3'].'\';
$pass3 = \''.$_POST['pass3'].'\';
$status3 = \''0'\';
$user4 = \''.$_POST['user4'].'\';
$pass4 = \''.$_POST['pass4'].'\';
$status4 = \''0'\';
$user5 = \''.$_POST['user5'].'\';
$pass5 = \''.$_POST['pass5'].'\';
$status5 = \''0'\';
$user6 = \''.$_POST['user6'].'\';
$pass6 = \''.$_POST['pass6'].'\';
$status6 = \''0'\';
$user7 = \''.$_POST['user7'].'\';
$pass7 = \''.$_POST['pass7'].'\';
$status7 = \''0'\';
$user8 = \''.$_POST['user8'].'\';
$pass8 = \''.$_POST['pass8'].'\';
$status8 = \''0'\';
$user9 = \''.$_POST['user9'].'\';
$pass9 = \''.$_POST['pass9'].'\';
$status9 = \''0'\';
$user10 = \''.$_POST['user10'].'\';
$pass10 = \''.$_POST['pass10'].'\';
$status10 = \''0'\';
?'.urldecode('%3E');
$fx=fopen('datauser.php','w');
fwrite($fx,$data);
fclose($fx);
if($fx === false) {
header("Location: ./tokensettings.php?save=err");
}
else {
header("Location: ./tokensettings.php?save=success");
}
}
?>
Thank you so much.
Here is how my form looks like.
If you still want to do it your way you need to use the \ correctly for each ' to be included in the string even those in [ ] - not saying the final string produced would actually work but it is based on your code and my best guess at your desired result
<?php
$string1=' \'\'.$_POST[\'user1\']\'\';';
$string1=$string1.'\'\'0\'\';';
echo $string1;
?>
The whole urlencoding stuff is not needed at all, your quoting and escaping is messy and incorrect. and why not simply use file_put_contents? Use HEREDOC to avoid messy escaping.
file_put_contents('datauser.php', <<<CONTENT
<?php
\$user = '{$_POST['user']}';
\$pass = '{$_POST['pass']}';
\$status = '0';
CONTENT
);
but if you really want to use files as data storage, I would encourage you to save it in a data format like xml or json instead of writing php.
// save data to file ($_POST used as example...)
file_put_contents('user.json', json_encode($_POST));
// read data
$data = json_decode(file_get_contents('user.json'));
Hoping someone can help me with a Call to undefined function error I am getting in the following code:
$query = \FreePBX::Database()->query('SELECT model, dns, buttons, loadimage
FROM sccpdevmodel
WHERE dns > 0
ORDER BY model');
$res = $query->fetchAll();
foreach ($res as $row) {
$modelData['model'][] = $row[0];
$modelData['dns'][] = $row[1];
$modelData['buttons'][] = $row[2];
$modelData['loadimage'][] = $row[3];
}
return $modelData;
This first part seems to be ok then I get the error $modelData = sccp_get_model_data(); in this line.
<?php
$modelData = sccp_get_model_data();
$numModels = count($modelData['model']);
$addonData = sccp_get_addon_data();
$numAddons = count($addonData['model']);
?>
Any advice?
Here is a link to the source file if anyone can help please?
https://github.com/Cynjut/SCCP_Manager/tree/master
Make sure you are using an include or require statement to load your functions. I found what seems to be the full code base for this on github and didn't see where it loads in the functions you use.
Not sure if you want them conditionally loaded, but if not, you can include 'functions.inc.php'; at the top of the file that needs to use them.
i am working on a cakephp 2.x ... well the scenario is that i am sending messages to my webapp ... there are almost 509 messages ... the problem is it is saving some messages into db and on some messages it gives me an error on android console ... ...so first thing i want to ask what u all think that where the actual problem lies or can be lie..and the other think is there a way that i can throw some exception error on data which is not saving into the db .. so i can track the particular messages which is not saving into and causing the problem ...i need some help in debugging this code
here is my code
public function message(){
$this->loadModel('Message');
if ($this->request->isPost()){
$json = $this->request->data('json');
$data = json_decode($json, TRUE);
foreach($data as $datas){
$date = $datas['date'];
$mobileNo = $datas['mobileNo'];
$mobileNo = AllSecure::replaceDashesAndSpaces($mobileNo);
$body = $datas['body'];
$timestamp = $date/1000;
$date = date('Y-m-d h:i' , $timestamp);
$this->request->data['Message']['mobileNo'] = $mobileNo;
$this->request->data['Message']['body'] = $datas['body'];
$this->request->data['Message']['type'] = $datas['type'];
$this->request->data['Message']['User_id'] = $datas['idUser'];
$this->request->data['Message']['dateTime'] = $date;
$count = $this->Message->checkTextMessages($mobileNo,$body,$date,$datas['idUser']);
if($mobileNo!=null){
if($count>0){
}else{
$this->Message->create();
$this->Message->save($this->request->data
}
}
}
}
}
well i solved my problem by self ... i dont know why it is causing the problem ... so i did this .. and it works
foreach($data as $datas){
$i=0
$this->request->data['Message'][$i]['mobileNo'] = $datas['mobileNo'];;
$this->request->data['Message'][$i]['body'] = $datas['body'];
$this->request->data['Message'][$i]['type'] = $datas['type'];
$this->request->data['Message'][$i]['User_id'] = $datas['idUser'];
$i++;
if($mobileNo!=null){
}
}
$isSave = $this->Message->saveAll($this->request->data["Message"]);
echo $isSave;