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

    PLEASE HELP! Refresh code not working right! ><

    I need this script to detect if a user has javascript on. and if they dont, redirect them AUTOMATICALLY to enable_javascript.php where it will refresh every 5 seconds to check and see if they re-enabled javascript. and if they did, take them back to index.php

    PHP Code:
    I need this to refresh a page every 5 seconds

    and if it detects javascript is on then take user to index

    else

    refresh and stay on same page.

    <?php
    ob_start
    ();

    $js = (isset($_GET['js']) && $_GET['js']=='1') ? 0;
    if (
    $js)
    {
    ?>
    <?php
    $urlRefresh 
    "index.php";
    header("Refresh: 5; URL=\"" $urlRefresh "\""); // redirect in 5 seconds
    ?>
    <?php
    }else{
    $urlRefresh "enable_javascript.php";
    header("Refresh: 5; URL=\"" $urlRefresh "\""); // redirect in 5 seconds
    }
    ?>
    blah
    <?php
    ob_end_flush
    ();
    ?>

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    pretty sure you don't need the quotes around the URL. You haven't really specified a problem with the script. Clearly you must have a problem but you haven't specified what it is
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I need this script to detect if a user has javascript on. and if they dont, redirect them AUTOMATICALLY to enable_javascript.php where it will refresh every 5 seconds to check and see if they re-enabled javascript.
    Wow, that's annoying. Why would you want to do such a thing?

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I couldn't agree more, plus the fact that some browsers don't have javascript so it would endlessly refresh
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    Yea, you guys are SOME help >< My site runs on javascript and I don't want people without javascript on my site because it won't work right.

    W/e, i'm going to solve this on irc. cuz you guys are NO help at all..

    Alls you do is complain

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    The refresh is pointless every five seconds. You should just redirect to a page with "JavaScript not enabled - Please change your settings and re-visit the site" or something like that. What is the point in wasting all that bandwidth with refreshes?

    And like I said, you havent specified a problem, so how do you expect people to help you ffs
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #7
    New Coder
    Join Date
    Mar 2009
    Posts
    89
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Thumbs up

    Hi,

    This is my pure and simple suggestion:
    PHP Code:
    <html>
    <head>
    <meta http-equiv="refresh" content="5;URL=<?php echo $_SERVER['PHP_SELF'];?>" />
    </head>
    <body>
    blah
    <script>
    location.href='index.php';
    </script>
    </body>
    </html>
    This page refreshes itself in 5sec. if JS is enabled -> go to index page
    Regards
    URL2SEO URL shortener and redirection services

  • #8
    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
    Yea, you guys are SOME help >< My site runs on javascript and I don't want people without javascript on my site because it won't work right.
    Then your site is poorly designed.

    W/e, i'm going to solve this on irc. cuz you guys are NO help at all..

    Alls you do is complain
    When such a retarded idea is mentioned, (and on a public forum where you are open to any opinion or suggestion), what do you expect? Btw, you've never had previous help? Nice way of showing gratitude if you have.

    Now, if you'd spent even five minutes looking at any documentation, you would know that the meta tag method posted above is the one you need. Header doesn't have a refresh option. Never did and probably never will.

  • #9
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by ShadowIce View Post
    Yea, you guys are SOME help >< My site runs on javascript and I don't want people without javascript on my site because it won't work right.
    My comment / question was honestly meant to help, in a round about way. I wanted to know why you'd want to do such a thing. If your goal is to have a "JS required" website, then simply place a message letting the user know and give them the option of enabling JS to view the site. Why find some rinky-dink way to redirect them and force them to enable it?

    The bottom line is, your goal should be designing an unobtrusive site that degrades gracefully when non-JS users or users with older browsers visit. That's the reasoning behind my "complaint".

    Quote Originally Posted by ShadowIce View Post
    W/e, i'm going to solve this on irc. cuz you guys are NO help at all..
    Yes! Because we all know IRC is the last bastion of humanity left in this cruel world. You will find NO criticism there!

  • #10
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Quote Originally Posted by MattF View Post
    Header doesn't have a refresh option. Never did and probably never will.
    http://stackoverflow.com/questions/2...sh-http-header

    Just wanted to call you on this MattF. Though it's not part of an official standard, it's very use in HTTP-EQUIV attributes in <head> sections of HTML is functionally identical to it's use in header() calls in PHP.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #11
    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 ComputerX View Post
    http://stackoverflow.com/questions/2...sh-http-header

    Just wanted to call you on this MattF. Though it's not part of an official standard, it's very use in HTTP-EQUIV attributes in <head> sections of HTML is functionally identical to it's use in header() calls in PHP.
    The term for that situation is 'correct', not 'call'. You 'call' someone when they are intentionally stating an untruth or similar. You 'correct' someone if they are unintentionally incorrect.

    Relying on practically undocumented and unofficial behaviour is hardly good practice, however. There's no guarantee that it will be consistent across various clients, however. I will concede the point that it exists though.


  •  

    Posting Permissions

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