ironmanro Posted February 29, 2016 Report Share Posted February 29, 2016 Salutare. Am o problema de genul: User1 intra pe site prima data si primeste gift1 Cand User1 intra din nou pe site primeste gift2 si tot asa pana se termina gifturile User2 intra pe site prima data si primeste gift1, apoi gift2, gift3.... Userii sunt identificati dupa IP. Pana acum am reusit sa fac asta: user intra pe site, se cauta ip in baza de date > daca nu e gasit se adauga si echo(1) > daca e gasit echo(2) <?php $db = new PDO( 'mysql:host=localhost;dbname=************', '*************', '*************' ); $ipData = [ ':ip' => $_SERVER['REMOTE_ADDR'] ]; $statement = $db->prepare(' SELECT count(*) FROM IP_used WHERE ip_address = :ip '); $statement->execute($ipData); if ($statement->fetchColumn() == 0 ) { // add to list $statement = $db->prepare(' INSERT INTO IP_used ( ip_address ) VALUES ( :ip ) '); $statement->execute($ipData); echo(1); } else { echo(2); } ?> Puteti sa ma indrumati in directia buna? Sunt mai mult decat incepator in domeniul asta. Multumesc. Quote Link to comment Share on other sites More sharing options...
ironmanro Posted February 29, 2016 Author Report Share Posted February 29, 2016 18 minutes ago, EssenceOfLife said: /* database:: userGifts structura: userid | gifts | received | dateofgiftreceived 1 gift1 yes 01.03.2016 */ //Ii oferim giftul #1 mai intai $gOne_prime = "INSERT INTO `userGifts`(userid, gifts, received, dateofgiftreceived) VALUES('1', 'Nuclear Bomb :: Allahu Akkbar', 'yes', '02.03.2016')"; $gifts = array( 'Nuclear Bomb :: Allahu Akkbar', 'Nuclear Bomb :: Hiroshima', 'Nuclear Bomb :: Russian Molotov' ); $query = "SELECT `gifts` FROM `userGifts` WHERE `userid` = 'sesiune::user'"; $thesushi = $query->get_row(); if(in_array($thesushi['gifts'], $gifts)){ //giftul exista, trecem mai departe } else { $getTimeofLastPresent = "SELECT `gifts` FROM `userGifts` WHERE `userid` = 'sesiune::user' ASC 0,1"; $gtlp = $getTimeofLastPresent->get_row(); if($gtlp['dateofgiftreceived'] < strtotime(date("d-m-Y"))){ //da urmatorul gift } } Eu as face ceva de genul, n-am testat dar poate te ajuta. Merci mult. Sa vad unde ajung de aici Quote Link to comment Share on other sites More sharing options...
Cronicles Posted February 29, 2016 Report Share Posted February 29, 2016 Si daca are ip dinamic ? Quote Link to comment Share on other sites More sharing options...
ironmanro Posted February 29, 2016 Author Report Share Posted February 29, 2016 3 minutes ago, Cronicles said: Si daca are ip dinamic ? Assigned static in intranet. Altfel alegeam abordarea cu cookie dar si alea pot fi sterse Quote Link to comment Share on other sites More sharing options...
Silviu Posted February 29, 2016 Report Share Posted February 29, 2016 In loc de IP si/sau cookies joaca-te cu asta: http://www.w3schools.com/html/html5_webstorage.asp 2 Quote Link to comment Share on other sites More sharing options...
ironmanro Posted March 1, 2016 Author Report Share Posted March 1, 2016 Am reusit sa fac ce mi-am propus in proportie de 70% (din cauza timpului) in schimb codul arata intr-un mare fel si mai e nevoie si de sanitize la sql. Cand termin o sa postez aici poate mai primesc niste idei/sfaturi. Multumesc tuturor. Fara ajutorul vostru nu as fi reusit. 1 Quote Link to comment Share on other sites More sharing options...
EAdrian Posted March 2, 2016 Report Share Posted March 2, 2016 15 hours ago, ironmanro said: sanitize la sql. PDO Quote Link to comment Share on other sites More sharing options...
ironmanro Posted March 4, 2016 Author Report Share Posted March 4, 2016 (edited) Buna seara! Scriptul cu gifturile a iesit super misto dar m-a dus cu gandul spre alta chestie care mi s-a parut interesanta. Un site rotator cu referal remover si unique ip/site. (cum am ajuns de la gifts la ideea asta nici eu nu stiu, probabil deprivare de somn si multa cofeina) <?php $ip = $_SERVER['REMOTE_ADDR']; $con=mysqli_connect('localhost','*******','********','*********'); $rezultat=array(); $siteuri=array(); $sql = "SELECT siteid FROM user_sites WHERE ip_address = '$ip'"; $result = mysqli_query($con, $sql); while($row = $result->fetch_array(MYSQLI_ASSOC)) {array_push($rezultat, $row["siteid"]);} $sql="SELECT siteid FROM sites"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_assoc($result)) {array_push($siteuri, $row["siteid"]);} $final = array_diff($siteuri, $rezultat); $nextvisit = $final[array_rand($final)]; if ( !empty($final)){ $sql = "INSERT INTO user_sites (ip_address, siteid) VALUES ('$ip', '$nextvisit')"; $insertip = mysqli_query($con, $sql); print_r($nextvisit); $sql = "SELECT url FROM sites WHERE siteid = '$nextvisit'"; $result = mysqli_query($con, $sql); while ($row = $result->fetch_assoc()){ $url=$row['url']; } $sql = "UPDATE sites SET visited_today = visited_today + 1 WHERE siteid = $nextvisit"; $result = mysqli_query($con, $sql); $sql = "UPDATE sites SET visited_total = visited_total + 1 WHERE siteid = $nextvisit"; $result = mysqli_query($con, $sql); mysqli_close($con); echo '<a href="'.$url.'" rel="noreferrer" id="autoclick"></a>'; echo "<script>document.getElementById('autoclick').click();</script>"; } else { echo 'No more sites for you!'; } ?> DB sites [siteid] [site_name] [visited_today] [visited_total] usersites [idu] [ip_address] [siteid] Aici am ajuns de m-am dat cu capul de pereti! Sau gresesc eu grav undeva sau array_rand() nu da rezultate tocmai random. De ce spun asta? 90% din vizite s-au dus la primul site dupa cum reiese din statisticile salvate in baza de date. La momentul asta nu imi vine in cap nici un fel de posibila rezolvare, de asta apelez la voi. Multumesc mult! P.S. Va rog sa nu radeti prea tare de mine, cum spuneam si in primul post, sunt incepator in domeniul asta, vreau sa invat, dar dupa o varsta e un pic mai greu.... Daca vedeti erori sau ucruri care se pot imbunatati va rog sa imi spuneti. P.P.S. Evercookie e dementiala ce idee de tracking dar ma intreb daca e si legala din prisma "legislatiei mUE" legata de cookies. Edited March 4, 2016 by ironmanro 1 Quote Link to comment Share on other sites More sharing options...