PDA

View Full Version : javascript/php



robo-techie
June 21st, 2003, 01:55 AM
hi..

im trying to run a php script on the onLoad of my page.. basically i wanna decrement a number that is stored in a text file.. i tried doing this, but it wouldn't work :(

<script language="JavaScript">
<!--
subt = function() {
document.write("<?php")
document.write("$handle = fopen(\"curon.txt\", \"r\");")
document.write("$contents = fgets($handle, 4096);")
document.write("$temp = sprintf(\"%d\", $contents);")
document.write("$temp--;")
document.write("fclose($handle);")
document.write("$handle = fopen(\"curon.txt\", \"w\");")
document.write("fputs($handle, \"$temp\");")
document.write("fclose($handle);")
document.write("?>")
}
// -->
</script>
..
..
..
<body onUnload="subt()">

any help would be appreciated :)

Jubba
June 21st, 2003, 01:59 AM
I think you would have to write the script in a php page, and onUnload call the page to decrease the number...

robo-techie
June 21st, 2003, 02:02 AM
oh.. haha yeah.. didn't think of that! thanks jubs, will work on that.. but would that open a new windows when i load in the php script or something?

can you show me and samples? :)

Jubba
June 21st, 2003, 02:02 AM
yeah, just to clarify, I am 100% sure that what you are doing wont work. :)

You are trying to use a Client-side language to write a server-side script...

You would have to call another page decrease the number and then close the page.

Jubba
June 21st, 2003, 02:04 AM
I don't have any samples, I can show you a code to decrease a number... I know nothing about Javascript...

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=24666&perpage=15&pagenumber=2

My first post on that page has a PHP script to increase a number by 1, just change the + to a -

yeah, but I'm not sure on the JAvascript part...

robo-techie
June 21st, 2003, 02:08 AM
oh okay then, i'll work that out :)

i do have the script to decrement the number already, thanks though

cheers!
ahmed

robo-techie
June 21st, 2003, 03:14 AM
i tried doing this:
<body onUnload="window.location.href = 'unl.php'"> but as i expected it didnt work, althought unl.php works fine when called directly from the browser..

.. where's lost when you need him :P