Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write javascript output to file on server

Status
Not open for further replies.

alpinemobile

Programmer
Jun 27, 2012
3
Hi.
So I have this HTML file that tests the user's screen resolution, and plugins installed using Javascript. So when the user accesses the page it sees: (e.g.) Your current screen resolution is 1024x768 and you have the following plugins installed: Plug-in No.2- Java Deployment Toolkit 7.0.10.8 [Location: npdeployJava1.dll], Plug-in No.3- Java(TM) Platform SE 7 U1 [Location: npjp2.dll], Plug-in No.4- Microsoft Office 2003 [Location: NPOFFICE.DLL]... I also need to save this information in a file on the server. All users are having firefox or chrome. How do I do this considering javascript can't write files on the server. I also don't want to use activex. Is there a way to redirect the javascript output to php?

<html>
<body>
<script language="JavaScript1.2">
document.write("Your current resolution is "+screen.width+"*"+screen.height+"")
</script>
<BR><BR>
<SCRIPT LANGUAGE="JavaScript">
var num_of_plugins = navigator.plugins.length;
for (var i=0; i < num_of_plugins; i++) {
var list_number=i+1;
document.write("<font color=red>Plug-in No." + list_number + "- </font>"+navigator.plugins.name+" <br>[Location: " + navigator.plugins.filename + "]<p>");
}
</script>
</body>
</html>

Thanks
 
You could use Ajax, and send all the data over to a PHP script to store.

forum1600

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Hi

You can do it the cheap way.
HTML:
[b]<html>[/b]
[b]<body>[/b]
[b]<script>[/b]
[highlight #ffc][b]var[/b] param[teal]=[/teal][green][i]'width='[/i][/green][teal]+[/teal]screen[teal].[/teal]width[teal]+[/teal][green][i]'&height='[/i][/green][teal]+[/teal]screen[teal].[/teal]height[/highlight]

document[teal].[/teal][COLOR=darkgoldenrod]write[/color][teal]([/teal][green][i]"Your current resolution is "[/i][/green][teal]+[/teal]screen[teal].[/teal]width[teal]+[/teal][green][i]"*"[/i][/green][teal]+[/teal]screen[teal].[/teal]height[teal]+[/teal][green][i]""[/i][/green][teal])[/teal]

[b]for[/b] [teal]([/teal][b]var[/b] i[teal]=[/teal][purple]0[/purple][teal],[/teal] num_of_plugins [teal]=[/teal] navigator[teal].[/teal]plugins[teal].[/teal]length[teal];[/teal] i [teal]<[/teal] num_of_plugins[teal];[/teal] i[teal]++)[/teal] [teal]{[/teal]
  document[teal].[/teal][COLOR=darkgoldenrod]write[/color][teal]([/teal][green][i]"<font color=red>Plug-in No."[/i][/green] [teal]+[/teal] [teal]([/teal]i [teal]+[/teal] [purple]1[/purple][teal])[/teal] [teal]+[/teal] [green][i]"- </font>"[/i][/green][teal]+[/teal]navigator[teal].[/teal]plugins[teal][[/teal]i[teal]].[/teal]name[teal]+[/teal][green][i]" <br>[Location: "[/i][/green] [teal]+[/teal] navigator[teal].[/teal]plugins[teal][[/teal]i[teal]].[/teal]filename [teal]+[/teal] [green][i]"]<p>"[/i][/green][teal]);[/teal]
  [highlight #ffc]param[teal]+=[/teal][green][i]'&'[/i][/green][teal]+[/teal][COLOR=darkgoldenrod]encodeURIComponent[/color][teal]([/teal]navigator[teal].[/teal]plugins[teal][[/teal]i[teal]].[/teal]name[teal])+[/teal][green][i]'='[/i][/green][teal]+[/teal][COLOR=darkgoldenrod]encodeURIComponent[/color][teal]([/teal]navigator[teal].[/teal]plugins[teal][[/teal]i[teal]].[/teal]filename[teal])[/teal][/highlight]
[teal]}[/teal]

[highlight #ffc]document[teal].[/teal][COLOR=darkgoldenrod]write[/color][teal]([/teal][green][i]'<img src="[URL unfurl="true"]http://example.com/your-php-script-which-registers-client-details.php?'[/URL][/i][/green][teal]+[/teal]param[teal]+[/teal][green][i]'">'[/i][/green][teal])[/teal][/highlight]
[b]</script>[/b]
[b]</body>[/b]
[b]</html>[/b]
As an [tt]img[/tt] tag is used, better make your PHP script return an image. ( An 1*1 transparent GIF will do it. )

Feherke.
[link feherke.github.com/][/url]
 
I may have not explained myself properly, but what I'm really looking to do is simply getting the javascript output that the user sees, also in a file on the server.
 
Actually, Feherke's code method is a simple and clever way of doing it.

By using a Php file as the src of the image, you can send anything you need to the PHP Script, without needing Ajax.

You'll receive everything in the $_GET variable, for you to process and insert into the DB.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top