0

I was wondering if it is possible to use a server-side scripting language, php preferable, to automate the change of a value, in this case a number.

JS FILE (sample):

var whatIsShowingNow = 2;

function showChange(integral) {

   //code is written

}

and when calling it,

showChange(2);

The sample above which uses the Jquery framework, has the number 2 for the variable/function whatIsShowingNow and showChange for example.

The idea is that I want to have the automation of changing it to 3 after 14 days for example, then 4 14 days after that, and so on.

After some research it came to my understanding that changing the .js file to a .php file may assist in its editing/changing, but not quite sure, in A) its practicality and B) if its in good practice.

So is it possible to automate the value of a javascript variable and function to a specific timer on the server? Or, is there a better way of going around this?

I can just edit the value manually, but in dealing with a lot of code I was wanting something that could automate the change.

Thanks in advance for any assistance.

user1648449
  • 97
  • 2
  • 10

2 Answers2

0

Suggest: include two files: second is static file with the functions. First would be file producted by php in any request. somthing like:

<script src='mydomain/js_file.php?randomKey'></script>
<script src='mydomain/js_file.js'></script>

I'm not sure if the best way would not be simply write inline js by php.

anysite
  • 148
  • 1
  • 12
  • Thank You for the assistance but it's not quite what I was trying to do. As stated to **Maetuji**, I was looking to have the server auto-increment the number every fortnight for example. I tried to use the php write to a txt file method. Eg- `$fp = fopen(filename "r")...` I was trying to have it open the file, read the number in it then write the following number in replace of it, but couldn't get it to work. Thanks for the help though. – user1648449 Jan 07 '14 at 05:55
0

Well I don't know if it's good practice and/or safe, but I use the method you mentioned. I change the .js ending to .php and then you can easily include php code into the js file. Example

function showChange(<?=$_POST['something'];?>) {
//code is written
} 

I suggest you play with it and see if it fits you.

maetulj
  • 1,032
  • 1
  • 9
  • 15
  • Thanks for the help and idea, but it's not really what I was after. I was basically trying to utilise php's date/timestamp (UNIX format) to auto-increment the number in the javascript file. So, basically a php file that would change `2` to `3`, `3` to `4` every fortnight for example. – user1648449 Jan 07 '14 at 05:50