# Javascript/php

**URL:** <https://forum.kirupa.com/t/javascript-php/23701>\
**Category:** Uncategorized\
**Created:** [June 21, 2003, 5:55am UTC](https://forum.kirupa.com/t/javascript-php/23701 "2003-06-21T05:55:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![robo\_techie](https://avatars.discourse-cdn.com/v4/letter/r/b5e925/32.png) [@robo\_techie](https://forum.kirupa.com/u/robo_techie)\
**Post date:** [June 21, 2003, 5:55am UTC](https://forum.kirupa.com/t/javascript-php/23701/1 "2003-06-21T05:55:01Z")

</div>

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 ☹

```php
<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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 5:59am UTC](https://forum.kirupa.com/t/javascript-php/23701/2 "2003-06-21T05:59:57Z")

</div>

I think you would have to write the script in a php page, and onUnload call the page to decrease the number…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 6:02am UTC](https://forum.kirupa.com/t/javascript-php/23701/3 "2003-06-21T06:02:36Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 6:02am UTC](https://forum.kirupa.com/t/javascript-php/23701/4 "2003-06-21T06:02:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 6:04am UTC](https://forum.kirupa.com/t/javascript-php/23701/5 "2003-06-21T06:04:16Z")

</div>

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](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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 6:08am UTC](https://forum.kirupa.com/t/javascript-php/23701/6 "2003-06-21T06:08:22Z")

</div>

oh okay then, i’ll work that out 🙂

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

cheers!  
ahmed

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 21, 2003, 7:14am UTC](https://forum.kirupa.com/t/javascript-php/23701/7 "2003-06-21T07:14:08Z")

</div>

i tried doing this:

```php
<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 😛
