1

I'm trying to enable screenshots of the page a logged in user is currently on. I've placed a button that needs to:

  • read in the content of the referring page
  • save it to a file
  • render that file as a PDF
  • redirect back to the referring page

The problem I've run into is that users are logged in and on pages that are very specific to them. I can't grab the page via CURL with generic credentials because the screenshot won't be applicable, and I don't have the user's credentials.

How can I read in the contents of the current/referrering page with PHP without access to the users credentials? I've tried file_get_contents which was not working either.

Chords
  • 6,720
  • 2
  • 39
  • 61

2 Answers2

1

I don't believe this can be accomplished ethically without obtaining the user's credentials.

chaoskreator
  • 889
  • 1
  • 17
  • 39
1

It sounds like your mechanism is going to be faulty anyway: you're not saving the page as it looks to them, but rather saving the page as it looks to CURL at some point in the future.

If you want an accurate solution, then you need to save a copy of the rendered HTML somewhere server-side as you send it out (you can use PHP's output buffering to capture it) and mark the file you save with some sort of key that goes to the user. If the user clicks the button, it sends that key to the server which you use to look up the saved HTML file, and process it as desired.

Significantly less efficient, of course, but there you go. Alternately, you can save just the parameters processed in the page such that you can re-render it with PHP if required. Still no curl involved, but less saving going on. Obviously you don't need to keep this cache information long; just a few minutes, so storing it in ram (e.g. memcache) would be sufficient.

tylerl
  • 30,197
  • 13
  • 80
  • 113
  • Thanks, Tyler, great ideas. I think what I'll do is have the PDF link reload the page with the same query parameters, plus a new one to use to trigger the output buffering stuff. I haven't worked with that yet, so thanks for the recommendation. – Chords Jun 22 '12 at 15:41
  • Just wanted to follow up for anyone else reading this to say that all went smoothly. Saving to a temp file, grabbing the screen shot, then deleting the temp file worked flawlessly. – Chords Jun 25 '12 at 13:20