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
system
June 21, 2003, 5:59am
2
I think you would have to write the script in a php page, and onUnload call the page to decrease the number…
system
June 21, 2003, 6:02am
3
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?
system
June 21, 2003, 6:02am
4
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.
system
June 21, 2003, 6:04am
5
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…
system
June 21, 2003, 6:08am
6
oh okay then, i’ll work that out
i do have the script to decrement the number already, thanks though
cheers!
ahmed
system
June 21, 2003, 7:14am
7
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