views:

29

answers:

2

Thanks in advance for whoever can help with this question. I have build a messageboard-database using html forms, PHP, and my SQL. The website allows people to post topics and then post messages for each topic. They can then vote up or down on each message.

Right now, I do all that through a single PHP page and I use POST. When I used GET, every time I used the 'back' and 'forward' buttons, it would ask if I wanted to resend the form (very annoying). I want to protect the data, so I switched to POST, but if someone hits refresh after voting, it votes a second time. How can I fix that? Shouldn't the 'POST-ed info' be refreshed, too?

I am also thinking of making the initial presentation of the topic page (that comes up after they click on the topic name from a search) be presented through GET, using a separate PHP page for it. This way the url for the topic page can be linked to (since the actual topic is in the URL, as opposed to the POST page, where the topic is not in the URL). Though, even if I do this, after someone clicks to vote, the resulting page is identical except that the URL won't have the topic in it (since it is through POST now), and people may not realize they could link to it at all. Is there a way that after voting through the POST option, the page gets redirected to the GET version?

Finally, my main question is about SEO. I want the topic pages to be searchable on google. So I am thinking of having PHP dynamically generate static HTML pages. Is this the only way to do it? Should I have them made on the fly? Or just all generated once a day? I figure that when people vote up or down on a message within an HTML page, this would trigger the loading of the respective PHP page through POST. But then it begs the question.. if I want to post a link to a particular topic page (or if i set it up so people can link to one off facebook, for example), should I have it link to the static html page or to the url that creates it dynamically by using GET with PHP? Or should I use the HTML page but have it redirect to the GET page url? Or is there a way to just have GET page urls recognizable by google and have google provide links directly to them? I am thinking no, because they are dynamically generated each time, as opposed to static HTML. Does it matter if I put links up out there to the PHP page, but google directs people to the stat HTML version? I feel like the best thing for SEO would be to keep everything consistent so all the 'hits' are added up together.

Sorry for so many questions, but I think these are timely issues that affect most database sites that want their pages to be searchable in google.

A: 

just keep using POST requests and after you have stored a set of data in the database do a redirect.

header('Location: /myPage.php?voteSuccess=1');
exit;

then you won't have problems with multiply entered data when refreshing the page. also like this you can easily depending on the get-param print a notification on the page that the vote was successful.

you mustbe sure that before the call of the header() function no data has been sent to the client ie. by an echo/print etc. otherwise the cal lto header() will result in an error

to answer your second question, just make all content available via get-params. be sure they are linked somewhere (ie. using <a>-tags) on a page google already knows. a link to your mainpage, wihch then has links to your detail pages will be enough to let google find all your content.

tehre are also html meta-tags to tell the spider-bots how often you would like them torevisit the page and check for updated contents etc... but well in the end SEO this is a compelx subject and i don't think you can learn enough about it by asking questions here. if you want to get into it you spuld really read a book or at least some good tutorials...

zolex
A: 

Here are a couple of things for you to look into:

Regarding the refresh causing a re-vote, you can fix it a couple of different ways. Some people will use cookies/session variables. Another method would be just to set another flag, whose default value is 0, and increment it upon POST. If the flag is 1 (refreshed) then don't POST.

IMHO do not go down the road of exporting static HTML and writing into the file system. That's overkill for what you need -- URL rewrite. There are several options. It's very cool. Look it up.

The way URL rewrite works is this: your href tags will get written (programatically) in your PHP with the "friendly" appearance you desire. The URL rewriter will interpret bogus URL string (not counting the TLD of course) and decode your SEO optimized URL back into the URL variables you want to hide. The browser, having sent the bogus string as its request, shows only the pretty URL, and everyone's blissfully unaware of the ugliness underneath it all.

There are some tricks and best practices involved in architecting the optimal URL. If you're not careful you'll cause some new problems for yourself. I can't stress enough that you REALLY want to start sketching out your friendly URLs in advance of implementing it and compare it logically to other very large sites.

Good luck!

Chris Adragna
Clarification: my suggestion of using a URL rewriter is in response to the comment "piggybacking" your question.
Chris Adragna