Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2010, 10:47 PM   PM User | #1
ShadowIce
Regular Coder

 
Join Date: Apr 2009
Posts: 264
Thanks: 24
Thanked 1 Time in 1 Post
ShadowIce can only hope to improve
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
();
?>
ShadowIce is offline   Reply With Quote
Old 02-06-2010, 11:46 PM   PM User | #2
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
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 :)
JAY6390 is offline   Reply With Quote
Old 02-06-2010, 11:52 PM   PM User | #3
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
Quote:
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?
bdl is offline   Reply With Quote
Old 02-06-2010, 11:53 PM   PM User | #4
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
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 :)
JAY6390 is offline   Reply With Quote
Old 02-07-2010, 12:33 PM   PM User | #5
ShadowIce
Regular Coder

 
Join Date: Apr 2009
Posts: 264
Thanks: 24
Thanked 1 Time in 1 Post
ShadowIce can only hope to improve
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
ShadowIce is offline   Reply With Quote
Old 02-07-2010, 12:37 PM   PM User | #6
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
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 :)
JAY6390 is offline   Reply With Quote
Old 02-07-2010, 01:07 PM   PM User | #7
koko5
New Coder

 
Join Date: Mar 2009
Posts: 89
Thanks: 5
Thanked 14 Times in 14 Posts
koko5 is an unknown quantity at this point
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
koko5 is offline   Reply With Quote
Old 02-07-2010, 02:15 PM   PM User | #8
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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.

Quote:
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.
MattF is offline   Reply With Quote
Old 02-07-2010, 02:34 PM   PM User | #9
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
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!
bdl is offline   Reply With Quote
Old 02-07-2010, 06:36 PM   PM User | #10
Lamped
Super Moderator


 
Join Date: Feb 2009
Location: England
Posts: 539
Thanks: 8
Thanked 63 Times in 54 Posts
Lamped will become famous soon enough
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
Lamped is offline   Reply With Quote
Old 02-08-2010, 12:36 AM   PM User | #11
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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.
MattF is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:39 PM.


Advertisement
Log in to turn off these ads.