Gayner Posted November 21, 2009 Share Posted November 21, 2009 On my Prayer request site, i let users Click a button to Pray for somone that has posted a pray, i got that all set up but. // connect to db... if ($_GET['id']) { $id = (int) $_GET['id']; $sql = "update table set column=column+1 where id=$id"; mysql_query($sql); } I want my users to beable to only Pray for a user once each, and then not beable to prayer for that user anymore, for each session how i do this? easy eh? Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/ Share on other sites More sharing options...
mikesta707 Posted November 21, 2009 Share Posted November 21, 2009 for each session? just do something like if (isset($_SESSION['pray'])){ //dont pray { else { //pray $_SESSION['pray'] = true; } don't forget to add session_start() at the beginning of your page Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962375 Share on other sites More sharing options...
Cardale Posted November 21, 2009 Share Posted November 21, 2009 To do this I believe you would have to simple add another session that is the checker session. If it is set and if you do a match search on the value to see if it has the usernames id then do let them even see it or something. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962376 Share on other sites More sharing options...
emopoops Posted November 21, 2009 Share Posted November 21, 2009 make another table with each column the user id and each row the user id update it for the users column when they pray set the user row they pray for to 1 Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962380 Share on other sites More sharing options...
Gayner Posted November 21, 2009 Author Share Posted November 21, 2009 To do this I believe you would have to simple add another session that is the checker session. If it is set and if you do a match search on the value to see if it has the usernames id then do let them even see it or something. How do I create another session? Or do i make a row in phpmyadmin that is the session name automatically? Sorry i am new on session BRB LOOKING INFO ON SESSIONS~ OK back Bro, so i just make a row in phpmyadmin in my table called "prayer" then do if $_SESSION['pray'] = bla bal echo = " you alrdy Prayed for this Prayer sorry ! " This is kinda getting it u guys ? But the Prayer needs to be set for each prayer / row that that i have Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962393 Share on other sites More sharing options...
mikesta707 Posted November 21, 2009 Share Posted November 21, 2009 you don't need to make a row in a mysql table to use sessions. Sessions have nothing to do with sessions really (as far as their mechanics go). I gave you an example in my first post, thats pretty much all you need to do. However, that's assuming you want them to only pray during a session (IE whenever they close the browser) or they can only pray once per prayer, or once a day/week/month etc. That would be different. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962394 Share on other sites More sharing options...
Gayner Posted November 21, 2009 Author Share Posted November 21, 2009 you don't need to make a row in a mysql table to use sessions. Sessions have nothing to do with sessions really (as far as their mechanics go). I gave you an example in my first post, thats pretty much all you need to do. However, that's assuming you want them to only pray during a session (IE whenever they close the browser) or they can only pray once per prayer, or once a day/week/month etc. That would be different. I have a table that has thousands of rows full of prayers. and that code i showed u makes it so if somone clicks on "Pray for this Prayer" it says "Prayed" or whatnot i'll enhance that, the thing is that i only want that user to only beable to Prayer once for that individual prayer request but still pray for other thousand's of em u know? Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962398 Share on other sites More sharing options...
emopoops Posted November 22, 2009 Share Posted November 22, 2009 to first know what u will do to block it, u first must know how often someone can pray for another person.. once a log in? if not, dont use sessions, once a day, then u need to use database and store the last date the person prayed for that person... and then check and see if is in the right timeframe u choose. sessions expire after a while and when people clear their cookies, it clars the sessions as well, people dont clear the database, thats why u should use it unlessu just want to do it one prayer to a person per logged in session. otherwise using a session makes absolutely no sense because someone can just log out and then log in and pray again... the session variable will be "destroyed". if thats what u want, to have them jus tbe able to do that then use sessions. $_SESSION[prayer] = "time or something here"; which still doesnt make sense then people can pray for multiple people u would need to make a lot of session variables....databse seems to do the trick here either way.... i vote database update the rows and column like my previous post but do it with a timestamp then check and see how long its been since they last prayed for that person and block it if it has been too short of a time for ur website needs. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-962954 Share on other sites More sharing options...
Gayner Posted November 25, 2009 Author Share Posted November 25, 2009 Sorry but emopoops is a troll. makes no sense. And.. How do i do this for each session for each row? because they can pray for 1 id and another id but i want it to check if still trying to pray for id 1 they cant only once a day seperate id's in row? how would i use sessions in this Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-965201 Share on other sites More sharing options...
emopoops Posted December 5, 2009 Share Posted December 5, 2009 no looks like u got it to work on ur site tho hon, but im not a troll. u just cant comprehend obviously Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-972099 Share on other sites More sharing options...
forumforme123 Posted December 8, 2009 Share Posted December 8, 2009 $prayerarray = array(); $_Session['prayerid'] = $prayerarray; . //other code . $prayerid = $_POST[''prayerid]; array_push($_Session['prayerid'], $prayerid); . //other code . //loop to check in Session if prayerid exist. I don't know if this will work, I am also a php newbie, learning as I go along... And I don't know if you can take the session and treat it as an array to push item into it. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-973229 Share on other sites More sharing options...
emopoops Posted December 10, 2009 Share Posted December 10, 2009 make sure u dont mess up Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-974514 Share on other sites More sharing options...
oni-kun Posted December 10, 2009 Share Posted December 10, 2009 What I'd recommend is adding them to the session through a simpler manner (such as what forumforme123 states) $_SESSION['commented_ids'] += "," . $_SESSION['last_idcommented']; Or something similar, then you can use explode in a loop, to find what ID's they commented on disallowing it. "123, 22, 411" would result, as a string of ID's they've commented on. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-974530 Share on other sites More sharing options...
raytri Posted December 10, 2009 Share Posted December 10, 2009 The OP needs to be clearer. He's mentioned only letting them pray once per id per session, and once per id per day. The former you can do with session variables; the latter would seem to require updating the database. The mechanism ought to be similar though, using oni-kun's example. You're either writing a comma-delimited series of ids to a session variable, or you're writing them to a database cell. Then whenever they click pray, you check to see if the id has already been prayed for. Or you could be proactive, and only display the "pray" button next to ids that haven't already been prayed for. If doing the "once a day" thing, you'll also need to figure out how you want to delete the ids from the database so that a person can pray again the next day. If you want to keep it simple, just run a cron job that deletes the contents of that cell at midnight every day. If you don't like cron jobs, you could write some code that checks the time whenever the user logs in. If its the first time the user has logged in that day, erase the contents of the "already prayed for" cell. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-974534 Share on other sites More sharing options...
KevinM1 Posted December 10, 2009 Share Posted December 10, 2009 Something to keep in mind is that sessions don't persist. If a user clicks on a prayer, logs out of the system, then logs in again sometime later, the session that recorded that click no longer exists, meaning the user can click on the same prayer again. If you want to permanently ban multiple clicks, you'll need to store the info some place permanent, like a db table. Thankfully, the db solution is simple. Create a new table that will contain only a user's id and a prayer's id. Whenever a prayer is clicked, check that table to see if that user already clicked on that prayer. If so, alert the user that they already clicked that prayer. Else, do whatever processing you normally do and add that user-prayer pair to that db table. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-974535 Share on other sites More sharing options...
emopoops Posted December 12, 2009 Share Posted December 12, 2009 yeah thats what i was stating the db way Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-975861 Share on other sites More sharing options...
oni-kun Posted December 12, 2009 Share Posted December 12, 2009 yeah thats what i was stating the db way And you need to state this, Why? Wait for the OP to tell us or mark it as resolved. Simple 'nough. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-975863 Share on other sites More sharing options...
emopoops Posted December 12, 2009 Share Posted December 12, 2009 well i just mad a point about it and someone thinks im a troll because sessions really seems like a unique way to do it if there is like going to be a pray a lot but not in one session. but i explained earlier in my previous previous. etc.. post why u would need to use database or why u would need to use session.s so condescending... i was just explaining more ok. Quote Link to comment https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/#findComment-975871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.