Hi guys!
So, I've just "finished" a like/dislike button plugin for my website. here's what it does:
you click either the like or dislike icon.
v v v v
the button links to the current page with the GET commands of "action" (set to like or dislike) and "redirect" (the current URL).
v v v v
your choice is added to the database by the page, then you are redirected to the rediretc url (back where you came from). This is to stop the vote being resent every time you refresh the page.
v v v v
you return to the page you were at before.
HOWEVER!
If the URL you're voting from already had a variable in it (e.g. the id number for my comics page), the redirect does not work as the variables already in the URL screw it up.
To see what I'm talking about take a look here though you will need to log in to vote.
If I try to vote on that page I end up with
http://www.accidentalgames.com/comics.php?id=2?action=like&redirect=http://www.accidentalgames.com/comics.php?id=2
If I try again, it isn't cleared and I get
http://www.accidentalgames.com/comics.php?id=2?action=like&redirect=http://www.accidentalgames.com/comics.php?id=2?action=like&redirect=http://www.accidentalgames.com/comics.php?id=2?action=like&redirect=http://www.accidentalgames.com/comics.php?id=2 and so on.
Suggestions for alternative methods or solutions to the current problem are welcome!
I realise I haven't structured the above very well so sorry about that. I realise I could probably fix it by using POST rather than get, but would like to avoid doing that if possible.
Last edited by sparks (2011-10-21 13:46:33)
Offline
What does the code on the page the like button is on look like?
Offline
sparks, I think you're much better off using a separate page for the plugin.
Here's how I envision it:
- Using AJAX to avoid page refresh
- Clicking the button sends a request to rate.php?action=like&comic=3
- Button changes/hides once clicked. If page is refreshed, the button should be automatically removed from the page during the PHP preprocessing.
Offline
I think this might work, but Im just guessing. Maybe, for example the url is http://example.com?yes=no, replace that with <http://example.com?yes=no> so the <> are aroudn the url. Then on the like script, just do replace < or > with NULL. so it might work.
EDIT: then so if you were liking the url, example.com?yes=no, you would go to accidentalgames.com/like?url=<http://example.com?yes=no>. it shouldn't get mixed up with the GET parts that way.
Last edited by WindowsExplorer (2011-10-23 13:37:33)
Offline
bbbeb wrote:
sparks wrote:
AJAX... Yet another language to learn
![]()
JavaScript and PHP? Not too hard
![]()
More like one JS function and adapted PHP code...
Offline
I'm thinking, doesn't setting a variable on a page to the contents of another page trigger the php scripts on the page it's reading?
Couldn't I, for example, set a javascript function to the like/dislike button that sets a variable to "like.php?action=like" and then nothing else? The process of reading the page to the variable might cause the MySQL database to update and add the vote without me having to learn any AJAX
Offline
sparks wrote:
I'm thinking, doesn't setting a variable on a page to the contents of another page trigger the php scripts on the page it's reading?
Couldn't I, for example, set a javascript function to the like/dislike button that sets a variable to "like.php?action=like" and then nothing else? The process of reading the page to the variable might cause the MySQL database to update and add the vote without me having to learn any AJAX![]()
How would you set the variable to the contents of the page though? The answer is an XMLHttpRequest, aka AJAX
Offline