Log in

View Full Version : Reset Notices


Tasking Mickey
04-16-2011, 06:18 PM
Does anyone know of a php file, that when you go to it, any notices that you dismissed reappears, then drops you back at the forum index.

I have the file from another site,

<?php
if ($_COOKIE['bbuserid']==0 || $_COOKIE['bbuserid']==null)
{ die('You must be logged in to reset dismissed notices.'); }
include('includes/config.php');
$con = mysql_connect("localhost",$config['MasterServer']['username'],$config['MasterServer']['password']);
mysql_select_db($config['Database']['dbname'], $con);
mysql_query("DELETE FROM tta_noticedismissed WHERE userid=" . $_COOKIE['bbuserid']);
mysql_close($con);
echo '<script type="text/javascript">
<!--
window.location = "http://toontowners.com/forums/"
//-->
</script>';

?>

But dont know how to re-put it, so it can work on my forum.

Any help?

kh99
04-16-2011, 07:59 PM
It looks like you might be able to put that code in it's own php file, like maybe reset_notices.php, then enter the url (or make a link somewhere) that goes to http://toontowners.com/forums/reset_notices.php.

However...I'm not a security expert or anything, but I think the way $_COOKIE['bbuserid'] is used directly in the SQL is a security risk, so you probably don't want to do that unless you add some other access control for that file. (Or add code to make sure $_COOKIE['bbuserid'] contains only digits).

Tasking Mickey
04-16-2011, 08:09 PM
Yes, but how do I change that code, so when users on my site go to the link, http://mysite.com/forums/resetnotices.php, it would re-put the dismissed notices, then drop the users back at the forum index?

kh99
04-16-2011, 08:22 PM
Oh..well, if your database server is not 'localhost' then I think you'd want to use the server and port from the config file in place of "localhost", like:

$servername = $config['MasterServer']['servername'];
$port = $config['MasterServer']['port'] ? $config['MasterServer']['port'] : 3306;
$con = mysql_connect("$servername:$port",$config['MasterServer']['username'],$config['MasterServer']['password']);

Then change "http://toontowners.com/forums/" if that's not your forum.


ETA: and while we're at it, change the query line like this:
mysql_query("DELETE FROM tta_noticedismissed WHERE userid=" . intval($_COOKIE['bbuserid']));

to hopefully take care of that security issue.


Hope that helps.

Tasking Mickey
04-16-2011, 08:30 PM
So, I put that, in the place of $con = mysql_connect("localhost",$config['MasterServer']['username'],$config['MasterServer']['password']);

?

kh99
04-16-2011, 08:31 PM
Yes.

I haven't tried any of it, so there may be a typo I missed.

Tasking Mickey
04-16-2011, 08:42 PM
This is my resetdismiss.php file so far

<?php
if ($_COOKIE['bbuserid']==0 || $_COOKIE['bbuserid']==null)
{ die('You must be logged in to reset dismissed notices.'); }
include('includes/config.php');
$servername = $config['MasterServer']['servername'];
$port = $config['MasterServer']['port'] ? $config['MasterServer']['port'] : 3306;
$con = mysql_connect("$servername:$port",$config['MasterServer']['username'],$config['MasterServer']['password']);
mysql_select_db($config['Database']['dbname'], $con);
mysql_query("DELETE FROM tta_noticedismissed WHERE userid=" . intval($_COOKIE['bbuserid']));
mysql_close($con);
echo '<script type="text/javascript">
<!--
window.location = "http://toontownacres.com/forums/"
//-->
</script>';

?>

I uploaded that to my forums. then went to my http://mysite.com/forums/resetdismss.php, it redirected me back to my forums, but my dismissed notice didn't pop back up again.

Did I code something wrong?

kh99
04-16-2011, 08:48 PM
I actually don't know if that's the right code to un-dismiss notices. But there is one more thing I missed - that query has a table prefix (tta_) hard-coded and I guess that's not yours. So one more change:

mysql_query("DELETE FROM " . $config['Database']['tableprefix'] . "noticedismissed WHERE userid=" . intval($_COOKIE['bbuserid']));

Tasking Mickey
04-16-2011, 08:50 PM
YES! Thank you! Yes!

It worked! thank you so much! :)

cmmguy
07-11-2017, 01:13 PM
Thank you for this little script. I know this is old but others may find it useful.

One note- if you changed the cookie prefix then that has to be added to the cookie name. In the example above, the prefix is "bb" added to 'userid' and yours may be different. Otherwise, it works well.