?
Solved

Script not working...

Posted on 2008-10-15
11
Medium Priority
?
246 Views
Last Modified: 2010-04-21
I have this script that is not working... can someone please tell me why?


<?php
 
// Browser detection script using PHP Sniff
// http://phpsniff.sourceforge.net
 
// Set this to the URL for your site
$url='http://www.pragersoftware.com/'; // Trailing slash important!
 
// Include phpsniff code
require_once ('phpSniff.core.php');
require_once ('phpSniff.class.php');
 
// Instantiate phpSniff
$phpSniff=new phpSniff();
 
// Lookout for IE6 and below
if($phpSniff->browser_is('ie6') || $phpSniff->browser_is('ie5')) {
echo '<script type="text/javascript">document.getElementById("ldheLabel4").style.visibility="visible";</script>';
}
 
?>

Open in new window

0
Comment
Question by:rmmarsh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 22720588
Change the start of your script like so


<?php

error_reporting(E_ALL);
 
// Browser detection script using PHP Sniff
// http://phpsniff.sourceforge.net

and see what shows up. Also, make sure that the "require_once" scripts are being picked up. Try doing someting like this

require_once ('phpSniff.core.php') or die("Sniff core failed to load");
require_once ('phpSniff.class.php') or die("Sniff class failed to load");



0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 22720663
Darn! You always see these thing AFTER you post. Change the requires to includes. The "or die" does not on requires, but include_once does return a failure code.

See http://uk3.php.net/include_once

Sorry about that - don't know what was going through my head on that one..... :-(
0
 
LVL 82

Accepted Solution

by:
hielo earned 1600 total points
ID: 22720888
>>I have this script that is not working...
are you referring to the PHP portion? If yes, you probably do not have the correct path to the included files. Provide the full path. Assuming the files are at:
http://www.yoursite.com/includes/phpSniff.core.php

use:
require_once( $_SERVER['DOCUMENT_ROOT'] ."/includes/phpSniff.core.php");

If the problem is the javascript then use:
echo '<script type="text/javascript">window.onload=function(){document.getElementById("ldheLabel4").style.visibility="visible";};</script>';

Open in new window

0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:rmmarsh
ID: 22721700
It's not finding 'phpSniff.core.php' which is in the same directory as the .php page.

Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in /home/wwwmar1/public_html/sandbox2.php on line 37

Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwmar1/public_html/sandbox2.php on line 37

It appears it's looking for it in the usr/lib/php directory, of which I have no control... what do I do now?
line 37:  require_once ('phpSniff.core.php') or die("Sniff core failed to load");

Open in new window

0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 400 total points
ID: 22721941
Change the requires like so


// Include phpsniff code
require_once ('./phpSniff.core.php');
require_once ('./phpSniff.class.php');

That will force PHP to look in the current folder
 
0
 
LVL 82

Expert Comment

by:hielo
ID: 22722055
try:
require_once ( dirname($_SERVER['PHP_SELF']) . '/phpSniff.core.php');
 
0
 

Author Comment

by:rmmarsh
ID: 22722731
OK... I finally got the thing to find the sniff files... now, when I run it under IE 5, it doesn't display the label (as in the code below).  Is it coded correctly to display a label that is initially set as not visible?
if($phpSniff->browser_is('ie6') || $phpSniff->browser_is('ie5')) {
echo '<script type="text/javascript">document.getElementById("ldheLabel4").style.visibility="visible";</script>';

Open in new window

0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 1600 total points
ID: 22722934
The syntax is right. Most likely it needs the page to load first. try it as I suggested previously:
window.onload=function(){document.getElementById("ldheLabel4").style.visibility="visible";}

0
 

Author Comment

by:rmmarsh
ID: 22726460
OK... got it working without errors; however, it displays the label regardless of the browser (I only want IE below version 7)... I have placed this script in the head section.
<?php
// Browser detection script using PHP Sniff
// http://phpsniff.sourceforge.net
 
// Set this to the URL for your site
$url='http://www.pragersoftware.com/'; // Trailing slash important!
 
// Include phpsniff code
require_once( $_SERVER['DOCUMENT_ROOT'] ."/phpSniff.core.php");
require_once( $_SERVER['DOCUMENT_ROOT'] ."/phpSniff.class.php");
 
// Instantiate phpSniff
$phpSniff=new phpSniff();
 
// Lookout for IE6 and below
if($phpSniff->browser_is('ie6') || $phpSniff->browser_is('ie5')) {
 
echo '<script type="text/javascript">window.onload=function(){document.getElementById("ldheLabel4").style.visibility="visible";}</script>';
}
?>

Open in new window

0
 

Author Comment

by:rmmarsh
ID: 22726483
Ignore the last post... I forgot to name the file .php...
0
 

Author Closing Comment

by:rmmarsh
ID: 31506275
Thanks for the help, everyone... I appreciate it...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question