...

View Full Version : PLEASE HELP! Refresh code not working right! ><



ShadowIce
02-06-2010, 11:47 PM
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


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') ? 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();
?>

JAY6390
02-07-2010, 12:46 AM
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

bdl
02-07-2010, 12:52 AM
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?

JAY6390
02-07-2010, 12:53 AM
I couldn't agree more, plus the fact that some browsers don't have javascript so it would endlessly refresh

ShadowIce
02-07-2010, 01:33 PM
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

JAY6390
02-07-2010, 01:37 PM
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

koko5
02-07-2010, 02:07 PM
Hi,

This is my pure and simple suggestion:


<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 ;)

MattF
02-07-2010, 03:15 PM
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.

bdl
02-07-2010, 03:34 PM
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".



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! :rolleyes:

Lamped
02-07-2010, 07:36 PM
Header doesn't have a refresh option. Never did and probably never will.

http://stackoverflow.com/questions/283752/refresh-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.

MattF
02-08-2010, 01:36 AM
http://stackoverflow.com/questions/283752/refresh-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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum