views:

25

answers:

1

Hello guys,

my code is a bit messy so I'll try to explain to you in words:

I have this index.php page that shows a random file from my files table in my database. People have the opportunity to rate these files by clicking on notes that open "vote.php" through a small AJAX pop-up.

Now here's the problem. On index.php I pull the ID from the database and output it:

$_SESSION['file_id'] = $file_id;
echo $_SESSION['file_id'];

But when I open the vote.php pop-up and write:

session_start();
echo "SID="; echo $_SESSION['file_id'];

The value is not the same! What could cause this?

Thank you very much.

A: 

Without fixing this specific problem, I don't think $_SESSION is needed here.

Can't you open vote.php with

vote.php?file_id=xxxx

You just need to add the variable in the URL when you generate index.php.

No need for sessions here.

Loïc Février
Yeah I think I'm going to rewrite it and do it like this. At first I thought of the sessions because I thought I would avoid people finding the "trick". But I check their IP or their username (if logged) in voted.php anyway, so it's unnecessary.
If want to avoid people to vote too ofter you can allow only one vote every x seconds using session (IP is not that good : there can be a lot a people for just one IP, think of a router in a company).
Loïc Février
Interesting, but what's the maximum of seconds I can put? My goal would be to allow only one vote per lifetime.
Well the IP is changing so if you allow vote for unregistered users there is no way to do it...either only allow registered users for put a big constant, a few hours maybe...
Loïc Février
Yeah I'm aware the IP can change, but it's not the case for everyone. Currently I store the IPs in a table but the x seconds thing will be way lighter. Thanks!
Not for everyone but for the majority.
Loïc Février