Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 4 of 4
  1. #1
    Fanatic Enthusiast Niall's Avatar

    Join Date
    Aug 2007
    Posts
    3,298

    If JavaScript is disabled, execute PHP

    I'm trying out a file hosting site for giggles, and I'm using JS to detect the file type and decide whether or not it's allowed to be uploaded.
    I was wondering, what if the user has JS disabled? I'm sure I could run a simple file check with PHP, but I'm not sure how I'd do it.

    Any ideas?

  2. #2
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: If JavaScript is disabled, execute PHP

    PHP is unable to check whether or not JS is enabled but you can do simple work arounds.


    Have a hidden form field called, hasJavaScript, set it's value to false. Then on form submit call a javascript function which sets the value to true. Like;


    Code:
    function detect()
    {
       document.FORM-NAME.hasJavaScript.value = "true";
    }
    Grab the form post with PHP if true you know the user has javascript.

    I would still run PHP checks over the top of JS. Forms can easily be manipulated if not secured correctly.

  3. #3
    Fanatic Enthusiast Niall's Avatar

    Join Date
    Aug 2007
    Posts
    3,298

    Re: If JavaScript is disabled, execute PHP

    Thanks, that works great.

    I'm just wondering though, would I really need to check if it's disabled or not? I could just run the PHP check regardless.

  4. #4
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: If JavaScript is disabled, execute PHP

    It's entirely up to you whether you use a mixature.


 

Posting Permissions

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