Author Topic: PHP Help  (Read 5424 times)

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
PHP Help
« on: February 23, 2006, 12:14:04 PM »
Ive only worked with PHP a bit, so I thought it would be good idea to make a website using php/mysql to improve my skills a bit.

I also wanted to do something with XML, and thought of creating a guestbook with it instead of using MySQL, and people have done, so I thought I would give it a try.

1.  I wanted to keep a track of the number of posts people have made, is there a global variable I could store this information and update it evertyime someone submits an entry, or will I have to store it in a file?

2.  I havent worked with cookies before, but if I sent the user a cookie, would this prevent a script from continually posting messages?  Should I have an image next to the form and ask the user to input what the text in the image is?

Im sure Ill run into more problems as I go along, but I guess thats it for now.

Thanks

Hillbillie

  • Jackass II
  • Posts: 69
  • Karma: +11/-0
PHP Help
« Reply #1 on: February 23, 2006, 02:03:12 PM »
Quote from: Canuck
1.  I wanted to keep a track of the number of posts people have made, is there a global variable I could store this information and update it evertyime someone submits an entry, or will I have to store it in a file?


Short answer: there is no PHP-specific mechanism to provide you with this.

Long answer: global variables have a life-span, at best, as long as the user session; at worst, they last only for each page request. To store information longer than either of these two cases, you need a permanent data store... such as a database or a file.

Quote
2.  I havent worked with cookies before, but if I sent the user a cookie, would this prevent a script from continually posting messages?


Depends on how you use them.

Think of cookies as normal user input like GET and POST... except they work both ways (i.e., where GET and POST can only be used to send data from the client->server, cookies can do that as well as send data from the server->client). This means that if you were to send users a cookie that contained the number of posts they have made (or the time of the last post they made), it'd be very easy to abuse this from the client's standpoint, i.e. changing the number of posts they have made (or changing the time of the last post they had made), thereby bypassing your anti-spam system.

In conjunction with some sort of login or tracking system, cookies could help you out... but you'd only want to use them for authentication information.

Does that make sense?

Quote
Should I have an image next to the form and ask the user to input what the text in the image is?


Image verification is pretty simple, but requires you to have an image-rendering library installed and available to PHP, such as GD. (Most commercial hosts already have it installed.) Lots of examples of how to implement this are available online.

To answer your question, though, it depends. Are you going to have some sort of registering/login system? Or is this a anyone-can-sign-the-guestbook sort of thing? If it's the latter, I'd say image verification would be ideal, though it can be annoying for users. If you're going with the former, though, I'd say image verification for posting new messages isn't required. Image verification would definitely be the easiest to implement.

Any reason in particular you want to use XML instead of MySQL for your data storage?
« Last Edit: February 23, 2006, 02:07:16 PM by Hillbillie »
Reduced fat and now 100% pot free, but same great okay taste.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
PHP Help
« Reply #2 on: February 23, 2006, 02:20:58 PM »
I'm with HB on the storage bit... (and I agree with the rest as well).

Don't bother with XML for storage of data like you're trying to do.  XML is a transfer medium, IMO.  XML is good for RSS, and transporting data in a specified format.  Period. (in my book)  XML files are not meant to be updated and changed (and to do so usually requires rewriting the entire file).  This is what databases are designed for... storing and updating specific pieces of data.  I really don't get what the hype of XML is all about.  Databases are much more efficient in most cases and there are other (better, IMO) vehicles for display.

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
PHP Help
« Reply #3 on: February 23, 2006, 02:23:24 PM »
>>Does that make sense?
Yes

>>is this a anyone-can-sign-the-guestbook sort of thing
Yes it is, and Ill take a look into GD, thanks!

>>Any reason in particular you want to use XML instead of MySQL for your data storage?
Yes and no.  My host provides me with 5 dbs, Im already using 1, although I dont know what else I would use the other 4 for, I didnt really want to use it for a guestbook.  I also wanted to work with XML, I dont know how much more work it will create for me, hopefully not too much...

edit: I havent done much work with it, so its not too late to switch to using a db :), which I tihnk I will

Thanks

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
PHP Help
« Reply #4 on: February 23, 2006, 03:45:34 PM »
Keep in mind that you could use a single database for more than one application if necessary.  They're just tables and the tables don't have to relate.

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
PHP Help
« Reply #5 on: March 06, 2006, 02:33:19 PM »
Instead of starting a new thread, I thought I would add to this once since it deals with PHP and the guestbook which Im writing.

I have a file, guestbook.php which has my guestbook html form.  When a user submits an entry it goes to checkguestbook.php throught the action command of my form.

If the server detects an error, I display the errors and supply a link to go back and fix the entry.  The problem is whatever was entered is no longer in the form.

How would I be able to save the information inputted, so the user doesnt have to input it again?

Thanks

edit: Currently looking into sessions, Ill post more detailed questions if I run into any problems.
« Last Edit: March 06, 2006, 02:38:50 PM by Canuck »

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
PHP Help
« Reply #6 on: March 06, 2006, 02:44:29 PM »
make your link include the user supplied parameters

Back to Guestbook

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
PHP Help
« Reply #7 on: March 06, 2006, 03:38:25 PM »
Or even better, make the action the same as the form page.  Set your submit button to have a name, and use isset($_REQUEST['submit_button_name']) at the top of the page to decide whether you should try and process the info or show the form.  If you find an error, display the errors AND show the form.  In the form itself, you have a bunch of if statements:
Code: [Select]

if(isset($_REQUEST['first_name']))
   echo "input field with value set to above";
else
   echo "input field with value set to '' ";


I could show you an example, but I think you get the point.  Post again if you don't.