Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/182369-help-if-user-voted-block-them/
Share on other sites

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

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.

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?

 

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.

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

  • 2 weeks later...


$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.

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.

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.

 

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.