Jump to content


Photo

Extremely basic question


  • Please log in to reply
9 replies to this topic

#1 Saragon

Saragon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 May 2006 - 06:28 PM

I have a very basic question. I'm trying to use the following code to pick a browser-specific stylesheet (Mozilla and IE's minor differences tend to be magnified by this particular design.) I'm teaching myself PHP for this purpose, and am getting the following error messages:

Warning: main(/nfs/cust/0/93/06/660390/web/demos/scripts/browserdetect.php): failed to open stream: No such file or directory in /nfs/cust/0/93/06/660390/web/demos/rgproperties/index.php on line 7

Warning: main(): Failed opening '/nfs/cust/0/93/06/660390/web/demos/scripts/browserdetect.php' for inclusion (include_path='.:/usr/local/php/include') in /nfs/cust/0/93/06/660390/web/demos/rgproperties/index.php on line 7

Fatal error: Call to undefined function: browser_detection() in /nfs/cust/0/93/06/660390/web/demos/rgproperties/index.php on line 8

I know enough to know that this basically means browserdetect.php isn't being found, and I suspect that's because I'm not properly linking the file into my main index.php file. Is there a better way?

<?php
    include($_SERVER['DOCUMENT_ROOT'] . "/demos/scripts/browserdetect.php");
    $browsername = browser_detection(browser);
    print '>link rel="Stylesheet" href="rgstyle_' . $browsername . '"<';
?>
(The > and < in the last line are inverted solely because I can't make the LINK tag appear in the CODE block otherwise. I'm not that bad. ;) )

Oh, and the "browserdetect.php" script is courtesy of Harald Hope, and can be found at [a href=\"http://techpatterns.com/downloads/php_browser_detection.php\" target=\"_blank\"]http://techpatterns.com/downloads/php_browser_detection.php[/a].

#2 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 03 May 2006 - 06:36 PM

[!--quoteo(post=370995:date=May 3 2006, 01:28 PM:name=Saragon)--][div class=\'quotetop\']QUOTE(Saragon @ May 3 2006, 01:28 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I have a very basic question. I'm trying to use the following code to pick a browser-specific stylesheet (Mozilla and IE's minor differences tend to be magnified by this particular design.) I'm teaching myself PHP for this purpose, and am getting the following error messages:

Warning: main(/nfs/cust/0/93/06/660390/web/demos/scripts/browserdetect.php): failed to open stream: No such file or directory in /nfs/cust/0/93/06/660390/web/demos/rgproperties/index.php on line 7

Warning: main(): Failed opening '/nfs/cust/0/93/06/660390/web/demos/scripts/browserdetect.php' for inclusion (include_path='.:/usr/local/php/include') in /nfs/cust/0/93/06/660390/web/demos/rgproperties/index.php on line 7

Fatal error: Call to undefined function: browser_detection() in /nfs/cust/0/93/06/660390/web/demos/rgproperties/index.php on line 8

I know enough to know that this basically means browserdetect.php isn't being found, and I suspect that's because I'm not properly linking the file into my main index.php file. Is there a better way?

<?php
    include($_SERVER['DOCUMENT_ROOT'] . "/demos/scripts/browserdetect.php");
    $browsername = browser_detection(browser);
    print '>link rel="Stylesheet" href="rgstyle_' . $browsername . '"<';
?>
(The > and < in the last line are inverted solely because I can't make the LINK tag appear in the CODE block otherwise. I'm not that bad. ;) )

Oh, and the "browserdetect.php" script is courtesy of Harald Hope, and can be found at [a href=\"http://techpatterns.com/downloads/php_browser_detection.php\" target=\"_blank\"]http://techpatterns.com/downloads/php_browser_detection.php[/a].
[/quote]

Try without the $_SERVER var, IE

include("/demos/scripts/browserdetect.php");


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 06:54 PM

If you want to echo a string that contains HTML tags, use the function htmlentities() when you echo the string. For example:
<?php
$test_str = '<span style="font-weight:bold;color:red">This is red and bold</span><br>';
echo $test_str;  // will show in color and bold
echo htmlentities($test_str);  //will not format.
?>

Ken

#4 Saragon

Saragon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 May 2006 - 07:27 PM

Sadly, neither suggestion has worked.

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/demos/scripts/browserdetect.php");
$browsername = browser_detection(browser);
$cssincluder = '<link rel="Stylesheet" href="rgstyle_' . $browsername . '">';
print htmlentities($cssincluder);
?>

I've tried it with and without the $_SERVER prefix -- nothing doing. Is the "include" function even the right one to use? Is there some other way to link in external scripts that contain functions?

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 07:30 PM

Did you download this package? If so where did you put it?

Ken

#6 Saragon

Saragon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 03 May 2006 - 07:56 PM

[!--quoteo(post=371031:date=May 3 2006, 03:30 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 3 2006, 03:30 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Did you download this package? If so where did you put it?

Ken
[/quote]

I did (there's a link in my first post to it, I believe) and it's in the 'scripts' directory. It's a single file -- really just three functions.

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 May 2006 - 08:32 PM

Where is the 'scripts' directory in relation to your script?

kEN

#8 Saragon

Saragon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 04 May 2006 - 12:29 AM

[!--quoteo(post=371052:date=May 3 2006, 04:32 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 3 2006, 04:32 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Where is the 'scripts' directory in relation to your script?

kEN[/quote]

The home directory, where the 'index.php' file and the variant CSS files are stored, has two sub-directories: 'scripts' and 'images'. The latter contains only image files; the former contains the 'browserdetection.php' script in question. In other words, here's the relevant file list:

.\index.php
.\rgstyle_ie.css
.\rgstyle_moz.css
.\scripts\browserdetect.php

#9 eddedwards

eddedwards
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 05 May 2006 - 03:06 PM

might not be much help. but i do a fair bit of including and ive not had this problem. the only difference is that ive always used include_once(), or maybee you could try require_once(), i dont really know the difference but its worth a try.

just for debug purposes you could try just print_r() the include. see whats in there.

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 May 2006 - 03:46 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The home directory, where the 'index.php' file and the variant CSS files are stored, has two sub-directories: 'scripts' and 'images'. The latter contains only image files; the former contains the 'browserdetection.php' script in question. In other words, here's the relevant file list:

.\index.php
.\rgstyle_ie.css
.\rgstyle_moz.css
.\scripts\browserdetect.php[/quote]
Since the script is in a directory directly beneath your scripts directory all you need to do is
<?php include('./scripts/browserdetect.php') ?>
or
<?php include('scripts/browserdetect.php') ?>
Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users