0

Wondering if there is a way to send a "Screenshot" of sorts through a form using PHP?

Rather than passing the values to a script to be handled and formatted there, any way to just send the form as it's shown on screen?

Ideally without the browser window, just the actual webpage itself, similar to how the Fireshot plugin lets you take a screenshot and save it.

Dan Harris
  • 1,336
  • 1
  • 21
  • 44

3 Answers3

2

There is no way to do this, at least not in pure PHP.

It may become possible at some point to take a screen shot of the current document into a <canvas> element, and send that element to the server. But at the moment, as far as I know, there is no API for this in any browser.

Edit: There seems to be a way of doing this using Flash, although I'm not sure the technology used here is available as Open Source. See Can you take a "screenshot" of the page using Canvas?

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
1

No. You cannot take a screenshot of the user's browser without installing any extra plugins into it, and even then PHP would have nothing to do with it.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

The below method doesn't take a snapshot (as stated by others it's not possible) but this is a 'way' to capture the state of the form at the time the user clicks the snapshot button. This is not production code, this is just a possible way of tackling it. Again I stress that this isn't a real snapshot, but will achieve a similer purpose.

You could get jQuery to send the completed HTML form and fields via POST to a PHP script that interprets the HTML and renders/saves it.

// Some javascript file
$('#save_button').click(function(e) {
$.ajax({
   type: "POST",
   url: "save_form.php",
   data: "data=" + $('#form_id').html(),
   success: function(msg){
     alert("saved: " + msg );
   }
 });
});

And then in the PHP file save_form.php (You would want to id the snapshots somehow, either autoincrement a value, or send an id (timestamp, ip, etc) from the ajax request

<?php
// connect to db
// bla bla bla - you would obviously clean the POST data before insertion

$result = mysql_query("INSERT INTO snapshots (html_source) VALUES ({$_POST['data']})");

// test result etc
// no you have the html stored, which you can view below

?>

And finally have a renderer, say snapshot_render.php

<?php
// you would make a request based on an id
$result = mysql_query("SELECT html_source FROM snapshots LIMIT 1");

$row = mysql_fetch_array($result);
echo $row['html_source'];

?>
Chris
  • 54,599
  • 30
  • 149
  • 186