Page 3 of 4
Re: Suggestions for PHP 6
Posted: Tue Mar 03, 2009 8:13 am
by lovelf
PCSpectra wrote:easily, not like the methods we can use now for this
You mean checking in JS and AJAX'ing the details to the server?
It's actually pretty simple. The only inherent problem is, upon first visit, the system cannot know whether the user has it enabled/disabled so you can optionally wait until they click a link to "enter" your site or redirect them auto-magically and I'm not sure how SE's would handle that.
If your site is that dependent on JS/Flash I would suggest you reconsider your design as accessibility is probably out the window and SEO is probably not a concern for you, in which case, a redirect might be a good solution.

No, see simple PHP Javascript detection below:
Code: Select all
<?php $jp = $_POST['jpb']; ?>
<?php if($jp == ""){echo "<script type=\"text/javascript\">document.write('<form style=\"display:none;\" method=\"post\" name=\"jp\"><input type=\"hidden\" name=\"jpb\" value=\"y\"></form>'); document.jp.submit();</script>";} ?>
<?php
if($jp == ""){whatever you want for no javascript users, variables you can store with values for no javascript users, functions for no javascript users, etc a php include for the noscript users...}
else {all stuff for javascript enabled browsers} ?>
Even though is simple it has a small? problem, if the user goes into any document inside the site and hits the back button there is the: "do you want to resubmit the info pop up alert for javascript users that got the form sent"
Does anyone know of a workaround to this?
Re: Suggestions for PHP 6
Posted: Tue Mar 03, 2009 3:08 pm
by Weirdan
It's no different from redirect, only more noisy, as you noticed yourself. Here's implementation that does not have this problem:
Code: Select all
session_start();
if (!array_key_exists('jsEnabled', $_SESSION)) {
// first hit, detect js
echo "<script type='text/javascript'>window.location='{$_SERVER["SCRIPT_NAME"]}?jsEnabled=1';</script>";
$_SESSION['jsEnabled'] = false;
} else if (($_SESSION['jsEnabled'] === false) && !empty($_GET['jsEnabled'])) {
// redirect to get rid of '?jsEnabled=1' in url
header("Location: {$_SERVER["SCRIPT_NAME"]}");
$_SESSION['jsEnabled'] = true;
die();
}
if ($_SESSION['jsEnabled']) {
// content for js enabled browsers
} else {
// content for browsers with js disabled
}
Re: Suggestions for PHP 6
Posted: Wed Mar 04, 2009 8:27 am
by lovelf
Weirdan,
I tried the code above with the addition:
Code: Select all
if ($_SESSION['jsEnabled']) {
$ler = "javascript enabled";
} else {
$ler = "javascript disabled";
}
echo $ler;
But with javascript disabled I would still see enabled, what am I doing wrong?
Re: Suggestions for PHP 6
Posted: Wed Mar 04, 2009 4:42 pm
by Weirdan
lovelf wrote:But with javascript disabled I would still see enabled, what am I doing wrong?
Remember that the detection works
only on the first hit. If you tried it first with js enabled and than with js disabled, the fact that you had js enabled is remembered in SESSION. After testing it with js enabled remove cookies that the page has set to your browser and try again with js disabled.
I think people seldom disable javascript while browsing a site, so this situation is not handled by this snippet.
Re: Suggestions for PHP 6
Posted: Fri Mar 06, 2009 4:36 pm
by kaisellgren
Even the User Agent -header is optional. The web browser does not need to send it. You are a lucky boy if you even get that, not to talk about screen resolutions, etc. That does not really make any sense. PHP is a server side software, not a client side. Use JavaScript if you want that information.
Btw, on one of my websites (30 000 unique visitors a month), 99.86% of visitors have JavaScript enabled. Just a reminder, we live in a year 2009. Did anyone think about that?
EDIT: $_SESSION can work without cookies by submitting the value into the URL (GET).
Re: Suggestions for PHP 6
Posted: Sat Mar 07, 2009 1:54 pm
by lovelf
But if we could get screen resolution with PHP then we could serve the client better code cooked server side.
Re: Suggestions for PHP 6
Posted: Sat Mar 07, 2009 2:03 pm
by kaisellgren
lovelf wrote:But if we could get screen resolution with PHP then we could serve the client better code cooked server side.
PHP is capable of doing it. Why wouldn't it? The problem is that no web browser submit such information.
Re: Suggestions for PHP 6
Posted: Sun Mar 08, 2009 1:14 am
by josh
See whats being overlooked is the fact that javascript is presentation logic. Most ( I would hope ) would agree making 1 app that works with or without jscript is easier then trying to maintain two apps where anytime business logic changes you have to update both the jscript and non jscript versions. Why not just make it degrade gracefully. Use <noscript> tags instead of detecting with PHP.
Re: Suggestions for PHP 6
Posted: Sun Mar 08, 2009 1:40 pm
by lovelf
The thing with noscript tags is that there is more code sent to the client and sometimes the code does not validate on the W3C validator.
Is alright, it is just not possible now, that is why I suggested if there might be a way to make this available - regardless of the little importance it might have to some, since it could be important for others - on PHP6.
Re: Suggestions for PHP 6
Posted: Sun Mar 08, 2009 1:46 pm
by kaisellgren
lovelf wrote:The thing with noscript tags is that there is more code sent to the client and sometimes the code does not validate on the W3C validator.
Is alright, it is just not possible now, that is why I suggested if there might be a way to make this available - regardless of the little importance it might have to some, since it could be important for others - on PHP6.
God please...
PHP team should not do anything about this kind of stuff - at least not for as long as there are no standards about this.
Besides, if a browser sends any such information, it is already fetchable in PHP:
Code: Select all
$raw = file_get_contents("php://input");
That contains the raw data that was sent to the server (including possible screen resolutions, etc if such info was ever sent).
Re: Suggestions for PHP 6
Posted: Tue Mar 10, 2009 6:02 pm
by Weirdan
kaisellgren wrote:
Besides, if a browser sends any such information, it is already fetchable in PHP:
Code: Select all
$raw = file_get_contents("php://input");
That contains the raw data that was sent to the server (including possible screen resolutions, etc if such info was ever sent).
Actually that would return request body - unlikely that it will contain such data. Result of apache_request_headers() is much more likely to contains such information.
Re: Suggestions for PHP 6
Posted: Tue Mar 10, 2009 6:14 pm
by alex.barylski
Btw, on one of my websites (30 000 unique visitors a month), 99.86% of visitors have JavaScript enabled. Just a reminder, we live in a year 2009. Did anyone think about that?
1. My Blackberry has JS disabled by default. I assume that will remain the norm for mobile devices for some time to come.
2. 99.9% of your users will never exploit your web site either, does that make it right to neglect the remaining 1% who will?
I used to always use JS until I finally heard enough from other developers on here harping about building software that doesn't 'rely' on JS. Once I made the transition, I have to admit it led to a cleaner, lighter, faster, more reliable and stable application. I still use javascript extensively (AJAX, WYSIWYG, etc) but my applications do no rely on it, at least for critical funcitonality. Like when using a WYSIWYG the fallback is a plain text editor but it still remains usable, unlike a drop down menu which when disabled prevents a user from navigating a web site or application.
Cheers,
Alex
Re: Suggestions for PHP 6
Posted: Tue Mar 10, 2009 6:43 pm
by Benjamin
Here's a suggestion. Fix this crap:
viewtopic.php?p=525167#p525167
Re: Suggestions for PHP 6
Posted: Tue Mar 10, 2009 6:59 pm
by kaisellgren
PCSpectra wrote:1. My Blackberry has JS disabled by default. I assume that will remain the norm for mobile devices for some time to come.
2. 99.9% of your users will never exploit your web site either, does that make it right to neglect the remaining 1% who will?
And? That is no problem, you just fall back and do not collect statistics for those visitors.
Re: Suggestions for PHP 6
Posted: Tue Mar 10, 2009 9:52 pm
by crazycoders
Chris Corbyn wrote:Anonymous objects...
snipped out anonymous methods code
Unless wrong, this is part of php6 along with lambda expressions no?
Chris Corbyn wrote:Accessor synthesizers...
snipped out Accessor synthesizers code
Accessor synthesizers are simply get/set methods that are public but exist or not. If you wish to protect a variable from being armed in an object simply create a public function getvariable(){ return $this->privatevariable; } and don't create a setter.
I add this to my base object class that i always use:
Code: Select all
class system_object {
//Constructor of the class
public function __construct(){}
//Magic property handlers
public function __get($name){
if(method_exists($this, 'get'.$name)){ return call_user_func(array($this, 'get'.$name)); }
else{ throw new Exception('Property '.$name.' not found in '.$this.' ('.get_class($this).') or property is writeonly.'); }
}
public function __set($name, $value){
if(method_exists($this, 'set'.$name)){ call_user_func(array($this, 'set'.$name), $value); }
else{ throw new Exception('Property '.$name.' not found in '.$this.' ('.get_class($this).') or property is readonly.'); }
}
}