This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-21 13:45:18

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

php redirecting complications - solution anyone?

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)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-10-22 05:06:36

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: php redirecting complications - solution anyone?

What does the code on the page the like button is on look like?


http://i.imgur.com/zeIZW.png

Offline

 

#3 2011-10-22 16:00:51

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: php redirecting complications - solution anyone?

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

 

#4 2011-10-22 16:28:36

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: php redirecting complications - solution anyone?

AJAX... Yet another language to learn  hmm


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#5 2011-10-23 13:35:32

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: php redirecting complications - solution anyone?

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)


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#6 2011-10-23 13:37:20

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: php redirecting complications - solution anyone?

sparks wrote:

AJAX... Yet another language to learn  hmm

JavaScript and PHP? Not too hard  wink


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#7 2011-10-23 13:49:22

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: php redirecting complications - solution anyone?

bbbeb wrote:

sparks wrote:

AJAX... Yet another language to learn  hmm

JavaScript and PHP? Not too hard  wink

More like one JS function and adapted PHP code...  smile

Offline

 

#8 2011-10-24 04:41:43

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: php redirecting complications - solution anyone?

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  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2011-10-24 12:12:34

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: php redirecting complications - solution anyone?

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  smile

How would you set the variable to the contents of the page though? The answer is an XMLHttpRequest, aka AJAX  smile

Offline

 

Board footer