setcookie non working mybb
#1
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?
Reply
#2
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.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#3
Is a test code, then how can I solve?
Reply
#4
Use the database object for starters. The function output_page should be the last line in any file you create.
Reply
#5
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
Reply
#6
(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.
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply
#7
How can I do so that the user can vote once a day?
Reply
#8
The easiest way is to store their vote in the database. Make sure your database has columns for uid, dateline, and the pollid.
Reply
#9
My colums are http://prntscr.com/e8o70p
Reply
#10
Nobody can tell me how to make vote once a day by cookies in mybb? Wow
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)