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
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post

    PLEASE HELP! Can't get code to use header only one time if js=off!

    I can't get this code to stop redirecting more than one time if javascript is off

    PHP Code:
    <?php
    ob_start
    ();
    ?>
    <noscript>
    <?php
    header
    ('Location: enable-javascript.php');
    ?>
    </noscript>
    <html>
    <head><title>Test</title></head>
    <body>
    blah
    </body>
    </html>
    and dont tell me to use metas because they redirect WAY too slow even if i set it to 0. the whole point is to keep the user from seeing index.php at all if js is off

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,313
    Thanks
    4
    Thanked 207 Times in 204 Posts
    Add exit; after the header call.

    PHP Code:
    <?php
    header
    ('Location: enable-javascript.php');
    exit;
    ?>
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    didnt work

    i REALLY need this script

    because metas are WAY too slow

    even if u set them to 0

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    ..and make sure that there's no call to header() redirect in your enable-javascript.php page.

    PS: It's very pity to see the use of such a code by a regular user of CF
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    this is whats in enable-javascript.php:

    PHP Code:
    <head>
    <meta http-equiv="refresh" content="5;URL=<?php echo $_SERVER['PHP_SELF'];?>" /> 
    <title>403 Forbidden</title>
    </head>
    <body>
    <script> 
    location.href='index.php'; 
    </script> 
    <h1>Forbidden</h1>
    <p>You don't have permission to access <?php echo GetFileDir($_SERVER['PHP_SELF']);?>
    &nbsp;on this server.</p>
    <hr>
    </body>
    </html>

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    No help found on IRC then?

  • #7
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    Was I talking to u?

    I think not

  • #8
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    ANYWAY here's what i have:

    index.php:

    PHP Code:
    <?php
    ob_start
    ();
    ?>
    <?php
    if (isset($_POST['jstest'])) {
      
    $nojs FALSE;
      } else {
      
    // create a hidden form and submit it with javascript
      
    echo '<form name="jsform" id="jsform" method="post" style="display:none">';
      echo 
    '<input name="jstest" type="text" value="true" />';
      echo 
    '<script language="javascript">';
      echo 
    'document.jsform.submit();';
      echo 
    '</script>';
      echo 
    '</form>';
      
    // the variable below would be set only if the form wasn't submitted, hence JS is disabled
      
    $nojs TRUE;
    }
    if(
    $nojs){
    header('Location: enable-javascript.php');
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>test</title>
    <body>
    blah
    </body>
    </html>
    <?php
    ob_end_flush
    ();
    ?>

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by ShadowIce View Post
    Was I talking to u?

    I think not
    Technically, yes, you were. You were addressing, (and asking for responses from), every registered member on this board.

  • #10
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post

    Thumbs up

    Yea, and now I'm ignoring u

  • #11
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Slightly off topic (but just slightly): Why is it that people continue to help this guy? Every time he comes in here with a remedial issue I think he honestly believes his problems are the only ones worth solving... that we must drop everything and help him because he cannot figure out a lot of things that often take 5 seconds to Google... and when people offer constructive criticism he treats them like an idiot. I don't get it. :\
    Last edited by kbluhm; 02-08-2010 at 03:14 PM.

  • #12
    Regular Coder
    Join Date
    Jan 2010
    Posts
    101
    Thanks
    17
    Thanked 5 Times in 5 Posts
    ShadowIce, I suggest you learn PHP before coding it. Headers cannot be inserted after any raw HTML, therefor it cannot appear in a <noscript> tag. Try again buddy. By the way, you're gonna tear yourself a new one with the amount of bandwidth you're going to waste. And disallowing your site to anyone who doesn't have JS enabled is just dumb. Some people actually turn off Javascript because it really shouldn't be needed. My suggestion is make your site degrade when JS is turned off, don't completely repel and users that have it turned off.

    Edit: It's worth telling us any errors you encounter in the future, so we're not just shooting in the dark trying to solve you're retarded problems.


  •  

    Posting Permissions

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