MyBB Community Forums
setcookie non working mybb - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: setcookie non working mybb (/thread-208273.html)

Pages: 1 2


setcookie non working mybb - Skyne - 2017-02-13

This is my page of like.php


<?php
define("IN_MYBB", 1);  
include("global.php");  

eval('$page = "'. $templates->get("home").'";');  
output_page($page);  



$cookies = my_setcookie($prefix."mybbuser", $user['uid']."_".$user['loginkey'], $remember);



$connessione = mysql_connect("***", "***", "***");
mysql_select_db("***", $connessione);

$id = $_GET['id']; 
$voto = $_GET['voto']; 

$risultato = mysql_query("SELECT voto FROM serverh", $connessione);

if ($cookies == TRUE)

{

echo "<script type='text/javascript'>alert('You have already voted!');</script>
<meta http-equiv=\"refresh\" content=\"0;URL=/home.php\">";

}

else

{
mysql_query("UPDATE serverh SET voto = voto +1 WHERE id = '$id'");
 my_setcookie("$cookies", time() + 86400);
    header('location:/home.php');
}
mysql_close($con);
?> 


Itì's a like system by click on the button linked to the id of the table. Except that when I go to click to increase the score and I find myself no longer logged in. Its operation should instead allow me to vote once a day. How can I fix?


RE: setcookie non working mybb - Matt - 2017-02-13

Because you're setting cookies after outputting the page, which isn't going to work.

Also, you have SQL injection vulnerabilities in this code, and you shouldn't need to manually create a new MySQL connection.


RE: setcookie non working mybb - Skyne - 2017-02-13

Is a test code, then how can I solve?


RE: setcookie non working mybb - dragonexpert - 2017-02-13

Use the database object for starters. The function output_page should be the last line in any file you create.


RE: setcookie non working mybb - Skyne - 2017-02-13

I tried as you said. The problem remains the same. Click to increase the voting (votes + 1) and find myself re-login.
Instead it clicks should get rated only once and if I repeat the click telling me that I have already voted


RE: setcookie non working mybb - fizz - 2017-02-14

(2017-02-13, 05:54 PM)Skyne Wrote: I tried as you said. The problem remains the same. Click to increase the voting (votes + 1) and find myself re-login.
Instead it clicks should get rated only once and if I repeat the click telling me that I have already voted

There's really no reason you should you be creating a new db connection from within some sort of plugin, just use the $db global. You also shouldn't need to reset the mybbuser cookie, that's probably at least part of the reason it's logging you out. Once someone is logged in you don't need to keep resetting that cookie, MyBB will do it for you when it needs to.


RE: setcookie non working mybb - Skyne - 2017-02-14

How can I do so that the user can vote once a day?


RE: setcookie non working mybb - dragonexpert - 2017-02-14

The easiest way is to store their vote in the database. Make sure your database has columns for uid, dateline, and the pollid.


RE: setcookie non working mybb - Skyne - 2017-02-14

My colums are http://prntscr.com/e8o70p


RE: setcookie non working mybb - Skyne - 2017-02-15

Nobody can tell me how to make vote once a day by cookies in mybb? Wow