MyBB Community Forums

Full Version: setcookie non working mybb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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?
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.
Is a test code, then how can I solve?
Use the database object for starters. The function output_page should be the last line in any file you create.
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
(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.
How can I do so that the user can vote once a day?
The easiest way is to store their vote in the database. Make sure your database has columns for uid, dateline, and the pollid.
Nobody can tell me how to make vote once a day by cookies in mybb? Wow
Pages: 1 2