tags:

views:

39

answers:

3

Hello

I'm no expert on web development, and need to find a way to let the browser call a PHP routine on the server with the current document ID as parameter, eg.

http://www.acme.com/index.php?id=1

I then need to call eg. /change.php with id=1 to do something about that document.

Unless I'm mistaken, there are three ways for the client to return this information:

  • if passed as argument in the URL (as above), it will be available as HTTP referrer
  • by including it as hidden field in
  • by sending it as cookie

I suppose using a hidden field is the most obvious choice. Are there other ways? Which solution would you recommend? Any security issues to be aware?

Thank you.

A: 

You can also POST the data so it won't be seen in the URL with ’form method = "post" ’

All of these methods are, to a point, insecure as they can be manipulated by a savvy user/hacker. You could https your site, limiting any man in then middle attacks. Be sure to check and validate incoming data

Evan
A: 

Ajax is another option as well, and it allows you to send that information without refreshing the page.

Chetan
Thanks for the tip. Can some AJAX embedded in the page be able to read the ID of the page it's in, and use this information to call a server-side script?
I guess the obvious solution to my problem is updating the server-side code so that hyperlinks/forms in the HTML page already include this information, so the browser doesn't have to figure it out.
You can either add a hidden div with the page ID, and have the Ajax read the ID from that div to call the server-side script, or have the Ajax read the ID from the URL of the page or something like that.
Chetan
A: 
http://www.acme.com/index.php?id=1

The above url would be more "browser friendly" if you transform it into something similar to this:

http://www.acme.com/index/page/1

I am sure you can achieve this in Apache. Or Java Servlets.

Michael Mao
'Browser-friendly' (by which you probably mean user-friendly / readable) is debatable with an anonymous id. It **is** however language-agnostic, also big step towards cool uri's (..don't change).
Wrikken