While using this script my tracker only update seeds & leechers from http tracker only 1st Tracker of my torrent.
print("<tr><td class='desc'><b>" .T_("Torrent Stats"). ": </b></td><td valign='top' class='lista'>");
$seeders1 = $leechers1 = $downloaded1 = null;
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
while ($trow = mysql_fetch_assoc($tres)) {
$ann = $trow["url"];
$tracker = explode("/", $ann);
$path = array_pop($tracker);
$oldpath = $path;
$path = preg_replace("/^announce/", "scrape", $path);
$tracker = implode("/", $tracker)."/".$path;
if ($oldpath == $path) {
continue; // Scrape not supported, ignored
}
// TPB's tracker is dead. Use openbittorrent instead
if (preg_match("/thepiratebay.org/i", $tracker) || preg_match("/prq.to/", $tracker)) {
$tracker = "http://tracker.openbittorrent.com/scrape";
}
$stats = torrent_scrape_url($tracker, $row["info_hash"]);
if ($stats['seeds'] != -1) {
$seeders1 += $stats['seeds'];
$leechers1 += $stats['peers'];
$downloaded1 += $stats['downloaded'];
SQL_Query_exec("UPDATE `announce` SET `online` = 'yes', `seeders` = $stats[seeds], `leechers` = $stats[peers], `times_completed` = $stats[downloaded] WHERE `url` = ".sqlesc($ann)." AND `torrent` = $id");
} else {
SQL_Query_exec("UPDATE `announce` SET `online` = 'no' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $id");
}
}
Please correct It I haven't been able to solve this trouble.
In first code I think trouble is here
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=".$id.";");
This should work if $id is a php variable
The problem is that you are sending a http-scrape to an UDP-tracker.
UDP-tracker uses an entirely diffrent protocol: http://www.bittorrent.org/beps/bep_0015.html
Related
I am trying to display all records using jason in php.
but display all filed with null value.
I'm using postman for testing purpose.
I don't know what is the problem with that code. I getting null value only.
here is my code :
<?php
header('Content-Type: application/json');
$checkFields = "";
$REQUEST = $_SERVER['REQUEST_METHOD'];
if ($REQUEST == "POST")
{
include "DB/db.php";
$userlist = mysql_query("SELECT * FROM reg_services");
if(mysql_num_rows($userlist) > 0)
{
$p = 0;
$ph = array();
while($userlistdata = mysql_fetch_row($userlist))
{
$ph[$p]["UserId"] = $userlistdata['id'];
$ph[$p]["FirstName"] = $userlistdata['fname'];
$ph[$p]["LastName"] = $userlistdata['lname'];
$ph[$p]["Email"] = $userlistdata['email'];
$ph[$p]["Mobile"] = $userlistdata['mobile'];
$ph[$p]["Password"] = $userlistdata['password'];
$p++;
}
$json = array("success" => 1, "All_User_List" => $ph);
$jsonarray = json_encode($json);
}
}
else
{
$json = array("success" => 0, "message" => "Invalid Request Type(Use POST Method)");
$jsonarray = json_encode($json);
}
echo $jsonarray;
?>
please help me if you are know what is the error in code.
just replace this code with old one
$p = 0;
$ph = array();
while($userlistdata = mysql_fetch_array($userlist))
{
$ph[$p] = array();
$ph[$p]["UserId"] = $userlistdata['id'];
$ph[$p]["FirstName"] = $userlistdata['fname'];
$ph[$p]["LastName"] = $userlistdata['lname'];
$ph[$p]["Email"] = $userlistdata['email'];
$ph[$p]["Mobile"] = $userlistdata['mobile'];
$ph[$p]["Password"] = $userlistdata['password'];
$p++;
}
You need to tell PHP about arrays
while($userlistdata = mysql_fetch_row($userlist))
{
$ph[$p] = array(); // let PHP know it is an array
$ph[$p]["UserId"] = $userlistdata['id'];
$ph[$p]["FirstName"] = $userlistdata['fname'];
$ph[$p]["LastName"] = $userlistdata['lname'];
$ph[$p]["Email"] = $userlistdata['email'];
$ph[$p]["Mobile"] = $userlistdata['mobile'];
$ph[$p]["Password"] = $userlistdata['password'];
$p++;
}
just replace this while loop condition with olde one.
while($userlistdata = mysql_fetch_array($userlist))
now it's work
I'm trying to build a script that will download users from a db table and attach a new random IP to each user based on his state.
The problem is that I wrote a lot of code and there is still much Copy/Paste job to be done if I keep it with this approach.
Can someone point me to the right direction on how to properly do that?
So first I have 50 of these:
$California_Text = file_get_contents('state/California.txt');
$California_textArray = explode("\n", $California_Text);
$Idaho_Text = file_get_contents('state/Idaho.txt');
$Idaho_textArray = explode("\n", $Idaho_Text);
$Illinois_Text = file_get_contents('state/Illinois.txt');
$Illinois_textArray = explode("\n", $Illinois_Text);
$Indiana_Text = file_get_contents('state/Illinois.txt');
$Indiana_textArray = explode("\n", $Indiana_Text);
$Iowa_Text = file_get_contents('state/Iowa.txt');
Then I have 50 of these:
while($row = $result->fetch_assoc()) {
if (isset($row["state"])) {
foreach ($row as $value){
$California_randArrayIndexNum = array_rand($California_textArray);
$p_California = $California_textArray[$California_randArrayIndexNum];
$Texas_randArrayIndexNum = array_rand($Texas_textArray);
$p_Texas = $Texas_textArray[$Texas_randArrayIndexNum];
$Alabama_randArrayIndexNum = array_rand($Alabama_textArray);
$p_Alabama = $Alabama_textArray[$Alabama_randArrayIndexNum];
$Alaska_randArrayIndexNum = array_rand($Alaska_textArray);
$p_Alaska = $Texas_textArray[$Alaska_randArrayIndexNum];
$Arizona_randArrayIndexNum = array_rand($Arizona_textArray);
$p_Arizona = $California_textArray[$Arizona_randArrayIndexNum];
.....
Then I have 50 of these:
if ($row["state"] == "california") {
$stateip = $p_California;
}
else if ($row["state"] == "texas") {
$stateip = $p_Texas;
}
else if ($row["state"] == "alabama") {
$stateip = $p_Alabama;
}
else if ($row["state"] == "alaska") {
$stateip = $p_Alaska;
}
I'm pretty much sure that it's a bad approach.. Maybe there's a way to do all this with like 3 lines of foreach?
Something like this:
// holds your content
$state_content = [];
while($row = $result->fetch_assoc()) {
// check do we have state set
if (!empty($row["state"])) {
$stateip = getStateIpByName($row["state"]);
}
}
/**
* Returns random IP
*/
function getStateIpByName($state_name) {
$content = getStateContent($state_name);
return $content[array_rand($content)];
}
/**
* Returns your's state content by state name
*/
function getStateContent($state_name) {
// checks do we already have content for this state
if(!isset($state_content[$state_name])) {
// generate file name
$file_name = "state/";
$file_name .= str_replace(" ", "", ucwords($state_name));
$file_name .= ".txt";
$state_text = file_get_contents($file_name);
$state_content[$state_name] = explode("\n", $state_text);
}
return $state_content[$state_name];
}
There are probably some errors but you will get idea.
Store all states in an array and do all operations within a foreach block
$states=['california',..];
foreach($states as $state){
//Your code for one state
//Replace state name with $state variable
}
I am using forecast.io API to deliver weather data to my website. Sometimes the forecast.io API is down, which causes every single page on my website which uses the forecast.io API to return "Service Unavailable, unable to get file content errors"
This is what I'm using to gather the weather data from the API
<?php
include("assets/php/forecast.php");
$api_key = '123123123';
$latitude = $data->getLatitude();
$longitude = $data->getLongitude();
$forecast = new ForecastIO($api_key);
/*
* GET CURRENT CONDITIONS
*/
$condition = $forecast->getCurrentConditions($latitude, $longitude);
$temp = $condition->getTemperature();
$temp = $temp + 2;
$summ = $condition->getSummary();
$icon = $condition->getIcon();
$icon2 = $condition->getIcon();
$icon = str_replace('-', '_', $icon);
$icon2 = str_replace('-', ' ', $icon2);
$icon = strtoupper($icon);
$icon2 = ucfirst($icon2);
?>
I would like to include some sort of error handler where if the forecast.io API is unavailable, then this code doesn't get called.
This is the site where I had the problem
https://seek.estate/
https://seek.estate/buy/422-melbournes-most-liveable-home-sea-views-elevator-designer-masterpiece
This is what I changed
$forecast = new ForecastIO($api_key);
$request_url = 'https://api.forecast.io/forecast/';
$content = file_get_contents($request_url);
if (!empty($content)) {
return condition = $forecast->getCurrentConditions($latitude, $longitude);
} else {
return false;
}
I use Yii, and I get this error; What should I understand and do?
Not a duplicate of: source or any other;
error is at: ->bindParam(":url_id", $url->id)
$url = Url::model()->findByAttributes(array('link' => $_url));
if (empty($url)) {
$url = new Url();
$url->website_id = $website->id;
$url->link = $_url;
$url->title = '';
$url->description = '';
$url->doctype = $_doctype;
$url->visits = 1;
$url->created = date('Y-m-d h:i:s',time());
$url->updated = date('Y-m-d h:i:s',time());
$url->status = 1;
$url->save(false);
} else {
// update visits
$url->saveCounters(array('visits' => 1));
// url existed, let's load products
if (!Yii::app()->user->isGuest) {
$sql = "select u.id from url as u
left join url_follower as u_f
on u.id = u_f.url_id and u_f.user_id = :user_id
where u.id =:url_id";
$cmd = Yii::app()->db->createCommand($sql)
->bindParam(":url_id", $url->id)
->bindParam(":user_id", Yii::app()->user->id);
$url_id = $cmd->queryScalar();
The solution, tested:
$user_id = Yii::app()->user->id;
$url_id = $url->id;
$cmd = Yii::app()->db->createCommand($sql)
->bindParam(":user_id", $user_id)
->bindParam(":url_id", $url_id);
i m using the php code to exectue the code using the cron. i have set the cron time and command in cpanel also.
1). But whenever cron runs i receive a mail
/home/letsview/public_html/getfeed.php: line 1: ?php: No such file or directory
/home/letsview/public_html/getfeed.php: line 3: syntax error near unexpected token `'/home/letsview/public_html/wp-config.php''
/home/letsview/public_html/getfeed.php: line 3: `include_once('/home/letsview/public_html/wp-config.php');'
i have set this command in cpanel "/home/letsview/public_html/getfeed.php"
i have also tried this PHP: Error trying to run a script via Cron job and added this command on the top of the file /usr/local/lib/php/ but it still not working
Here is the code of cron file getfeed.php
<?php
#!/usr/local/lib/php/
include_once('/home/letsview/public_html/wp-config.php');
include_once('/home/letsview/public_html/wp-includes/wp-db.php');
include_once('/home/letsview/public_html/wp-admin/includes/file.php');
include_once('/home/letsview/public_html/wp-admin/includes/image.php');
include_once('/home/letsview/public_html/wp-admin/includes/media.php');
global $wpdb;
//property_type
$xml = simplexml_load_file("/home/letsview/public_html/letsviewproperties.xml",'SimpleXMLElement', LIBXML_NOCDATA);
$TotalPostadded = 0;
$TotalUseradded = 0;
foreach($xml as $child)
{
//Insert Post
$postdata = array();
$postdata['post_title'] = trim($child->title);
$postdata['post_content'] = trim($child->content);
//$postdata['guid'] = trim($child->url);
$postdata['post_status'] = 'publish';
$postdata['post_type'] = 'post';
$postdata['post_date'] = date('Y-m-d H:i:s');
//Insert Post Meta
$postmetadata = array();
$addresstext = trim($child->FullAddress->address1);
if($addresstext != ''){
$addresstext .= ', ';
}
$addresstext .= trim($child->FullAddress->address2);
if($addresstext != ''){
$addresstext .= ', ';
}
$addresstext .= trim($child->FullAddress->address3);
if($addresstext != ''){
$addresstext .= ', ';
}
$addresstext .= trim($child->FullAddress->address4);
$postmetadata['price'] = trim($child->price);
$postmetadata['property_type'] = trim($child->type);
$postmetadata['bed_rooms'] = trim($child->rooms);
$postmetadata['bath_rooms'] = trim($child->bathrooms);
$postmetadata['address'] = $addresstext;
$postmetadata['add_city'] = trim($child->city);
$postmetadata['add_state'] = trim($child->FullAddress->region);
$postmetadata['add_country'] = trim($child->FullAddress->country);
$postmetadata['add_zip_code'] = trim($child->postcode);
$postmetadata['other_guid'] = trim($child->url);
$postmetadata['post_from_feed'] = true;
//Insert Author(agent)
$authordata = array();
$authormetadata = array();
if(!empty($child->agent->agent_name)){
//Author data
$authordata['user_login'] = trim(pg_create_string($child->agent->agent_name));
$authordata['user_nicename'] = trim($child->agent->agent_name);
$authordata['display_name'] = trim($child->agent->agent_name);
$authordata['user_email'] = trim($child->agent->agent_email);
$authordata['user_url'] = trim($child->url);
$authordata['role'] = trim('agent');
$authordata['user_registered'] = date('Y-m-d H:i:s');
//Author meta data
$authormetadata['user_phone'] = trim($child->agent->agent_phone);
$authormetadata['user_address'] = trim($child->agent->agent_address);
}
foreach($child->pictures as $pictures)
{
$postimagedata = array();
$imageloop = 0;
foreach($pictures as $picture)
{
$postimagedata[$imageloop] = (string)$picture->picture_url;
$imageloop++;
}
}
$postmetadata['post_from_feed_images'] = serialize($postimagedata);
if($postdata['post_title'] != ''){
$sql = "select count(post_title) as post from ".$wpdb->prefix."posts where post_title = '".$postdata['post_title']."' and post_status = '".$postdata['post_status']."'";
$sqlresult = $wpdb->get_results($sql);
foreach ( $sqlresult as $post ) {
if($post->post == 0)
{
if(!empty($authordata)){
$user_id = wp_insert_user( $authordata );
if(!empty($user_id) && empty($user_id->errors)){
$TotalUseradded++;
echo "User added = ".$user_id."<br />";
if(!empty($authormetadata)){
foreach($authormetadata as $meta_key=>$meta_value){
add_user_meta( $user_id, $meta_key, $meta_value);
echo "User Meta = ".$meta_key." Inserted<br />";
}
}
}elseif(!empty($user_id->errors)){
$userdata = get_user_by('email', $authordata['user_email']);
$user_id = $userdata->ID;
echo "User fetched = ".$user_id."<br />";
}
$postdata['post_author'] = $user_id;
}
$post_id = wp_insert_post($postdata);
if(!empty($post_id)){
$TotalPostadded++;
echo "<br />"."Post Inserted = ".$post_id;
$properties_category_id = 109;
$cat = "INSERT INTO wp_term_relationships ( object_id, term_taxonomy_id ) VALUES ( '".$post_id."','".$properties_category_id."' )";
$catid = $wpdb->query($cat);
echo "<br />"."Post attached to Category ID = ".$properties_category_id."<br />";
if(!empty($postmetadata)){
foreach($postmetadata as $key=>$value){
add_post_meta($post_id, $key,$value, true);
echo "Post Meta = ".$key." Inserted<br />";
}
}
}
}
}
}
}
$cron = "<br />"."Corn Done";
$cron .= "<br />"."Total Post added = ".$TotalPostadded;
$cron .= "<br />Total User added = ".$TotalUseradded;
echo $cron;
mail('xxxxxx#xxxxx.com','Lets view Properties Corn',$cron);
function pg_create_string($text)
{
// replace all non letters or digits with -
$text = preg_replace('/\W+/', '-', $text);
// trim and lowercase
$text = strtolower(trim($text, '-'));
return $text;
}
?>
Can any one help me??
The start of the file should be:
#!/usr/bin/php
<?php
This assumes that your PHP binary is in the folder /usr/bin. If it isn't, then change the #! line appropriately.
Even better:
#!/usr/bin/env php
<?php
will almost certainly work as it uses the system's env command to work out where php is.
Add this to the very top of your file and chmod the file to execute rights (555 or 775) etc.
#!/usr/local/lib/php
<?php
// your code
Where /usr/local/lib/php is the path to php.
Or if that doesn't work you can change the cron command:
/usr/local/lib/php /home/letsview/public_html/getfeed.php
#!/usr/local/lib/php
<?php
// php code
And you sure the php cli in /usr/local/lib