SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stop user if Javascript is disabled - with PHP?

    Hi:

    i have an app where a user must have JavaScript. So, to make sure user has it, can I make something with PHP which don't let the users see a web page if Javascript is disabled??

    Thanks.
    ---------------------------
    Errors = Improved Programming.
    My Site

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the script HTML tag for your main content and noscript tag to let those who don't have JS know it's required. This is client-side only and has nothing to do with PHP.

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you want to use a PHP method I use the following on my login scripts.

    On your login form submit add the action

    HTML Code:
    onSubmit="javascript:document.forms.formname.java.value=true"
    Then in your login script some PHP on the lines of

    PHP Code:
    if ($_POST['java'] == 'false'){
       echo 
    'You must have Javascript enabled to Log In to our site, please enable your browsers Javascript and try again';
       exit;

    If javascript isnt enabled the POST variable will be false, if it is enables the onSubmit will set the value True
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What a horribly complicated way to do it. You can easily set up a form just using HTML that will tell the PHP whether JavaScript is enabled.

    Code:
    <input type="hidden" name="js" value="on">
    <noscript>
    <input type="hidden" name="js" value="off">
    </noscript>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Both of which can be subverted.

    What about setting a cookie in JS and reading it in PHP?

    Duh... the headers can be spoofed?

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Cookies are even easier to block or change than the form code would be.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like that adding a form field with <noscript> tag. its easier.

    Yeah, i agree. everything can be spoofed. so, i'll go with the easy way.

    this application will be on intranet and they won't have much purpose to try and break it.
    ---------------------------
    Errors = Improved Programming.
    My Site

  8. #8
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might wanna note though that the script + noscript paradigm has a hole in it - it cannot cater for levels of support, only a binary state. If a user is using a device with some, but not much, scripting capability - such as a mobile device, a screen reader or a legacy browser - then they'll get the scripted functionality, but they may still not be able to use the application if it requires more advanced scripting support.

    Really, noscript is a broken concept, and a better way of doing this is to use progressive enhancement, something like this:

    Code:
    <form id="gatekeeper" action="noscript-warning-page.html">
    	<fieldset>
    		<input type="submit" />
    	</fieldset>
    </form>
    
    <script type="text/javascript">
    
    document.getElementById('gatekeeper').onsubmit = function()
    {
    	this.action = 'everything-fine.html';
    	return true;
    };
    
    </script>
    Though of course, the best way of doing this is simply to build an application that doesn't depend on JavaScript

  9. #9
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.

    I am still learning and need to learn a lot.

    i understand about javascript, but somethings just can't be avoided.
    ---------------------------
    Errors = Improved Programming.
    My Site

  10. #10
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,198
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    You can also use a ajax request to set a session variable. Of course the user can go around this one as well, but there would be no need to add additional form tags to every form.

    To make it more secure you can use javascript to provide specific information about the browser on the request, then use it to verify the user. It is still possible to go around this, but for the normal users it would be almost impossible. Keep in mind you need to rely on information the browser sends to php as well, else you can validate it.


Bookmarks

Posting Permissions

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