Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    overwrite same file with javascript

    I want to make an rpg with a username and password login without a database,
    I was thinking, maybe i could make it when the user presses "sign up" the webpage creates a new file in the same directory that stores all their information. I researched it and realised it wasn't cross browser compatible. Therefore I came up with an idea to store all the users' information in a array.

    What i want to do is that when the user presses "sign up" it adds that user to the array and the html file overwrites itself so the new user is saved into the array

    Any ideas?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Array? Where do you want to hold that array? Arrays are stored in memory of the one machine running the current script/program. Did you think about persistent storage of that array?

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The array will hold the usernames and passwords in a seperate .js file

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    JavaScript running in a browser is a client-side language. JavaScript does not have any commands for reading or writing files. Modern browsers can read files on the server using an Ajax call, but otherwise JavaScript has no capability to read from, write to, modify or delete a file (except a cookie), communicate with the server, access a database, the client's operating system or the Windows registry, or alter the default behaviour of the browser.

    In short, what you are trying to do is not possible. And if it was anyone could see the usernames and passwords simply with View Source.


    Quizmaster: In US history, the body known informally as the Warren Commission appointed in 1963, investigated the assassination of which President?
    Contestant: George Washington

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by TheElect2049 View Post
    I want to make an rpg with a username and password login without a database,

    Any ideas?
    The only way I can think of to do that is with a server side script, called with or without AJAX, to access and edit a file the server. Ther server file could be a php file containing an array of usernames or just a plain text file.

    The only pure javascript way I can think of is to use MS specific code and features for IE which allow you to access the user's file system, but users will have to change their security settings to alllow you to this. So it's not practical for that reason plus it will only work in Internet Explorer.

  • #6
    New Coder
    Join Date
    Mar 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    :\ ohk thanks for the wise information i'll just use offline storage lol

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    Quote Originally Posted by TheElect2049 View Post
    :\ ohk thanks for the wise information i'll just use offline storage lol
    Hmmm....like paper tape? I have an old teletype machine you could use.

    Then any time you need to bring the storage online, you just have to walk over to the machine and collect the punched tape and feed it back in to the reader. Works great. At 10 characters per second, no less.

    Very modern technology. Heck, it was the ONLY thing to use in 1975 or so.

    **********

    Okay, I give up. What in the heck *DID* you mean by "offline" storage?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by Old Pedant View Post
    Hmmm....like paper tape? I have an old teletype machine you could use.

    Then any time you need to bring the storage online, you just have to walk over to the machine and collect the punched tape and feed it back in to the reader. Works great. At 10 characters per second, no less.

    Very modern technology. Heck, it was the ONLY thing to use in 1975 or so.

    **********

    Okay, I give up. What in the heck *DID* you mean by "offline" storage?
    Are you still in the last century?

    Okay, I give up. What in the heck *DID* you mean by "offline" storage?
    let google be guide you into the 21st century offline storage

  • #9
    New Coder
    Join Date
    Mar 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    =.= html5 offline storage? Haven't u guys heard about it?

  • #10
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    Quote Originally Posted by TheElect2049 View Post
    =.= html5 offline storage? Haven't u guys heard about it?
    I have and I posted a link for the old pedant.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Quote Originally Posted by TheElect2049 View Post
    =.= html5 offline storage? Haven't u guys heard about it?
    The difficulty is that not all browsers include all of the new APIs, and you may have to support older browsers that don't include any of them at all. In a few years things may well be different.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #12
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,444
    Thanks
    11
    Thanked 598 Times in 578 Posts
    Quote Originally Posted by TheElect2049 View Post
    =.= html5 offline storage? Haven't u guys heard about it?
    year ago, but that won't anyone store user names and logins. well, one could store one's own credential, but the point was to let more than one user login. i guess if you only play the rpg on one computer it would work. that sounds exciting...

    since localStorage is seen by only one computer, the size of your application pool is quite limited by localStorage. If you added w3p2p, i guess you could server from localStorage, but i don't see any mention of that in the thread...
    Last edited by rnd me; 03-27-2012 at 10:53 PM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •