Jump to content

Extremely basic question


Saragon

Recommended Posts

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:

[i]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]
I know enough to know that this basically means [i]browserdetect.php[/i] isn't being found, and I suspect that's because I'm not properly linking the file into my main [i]index.php[/i] file. Is there a better way?

[code]
<?php
    include($_SERVER['DOCUMENT_ROOT'] . "/demos/scripts/browserdetect.php");
    $browsername = browser_detection(browser);
    print '>link rel="Stylesheet" href="rgstyle_' . $browsername . '"<';
?>
[/code]
(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 [i]that[/i] 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].
Link to comment
https://forums.phpfreaks.com/topic/8991-extremely-basic-question/
Share on other sites

[!--quoteo(post=370995:date=May 3 2006, 01:28 PM:name=Saragon)--][div class=\'quotetop\']QUOTE(Saragon @ May 3 2006, 01:28 PM) [snapback]370995[/snapback][/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:

[i]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]
I know enough to know that this basically means [i]browserdetect.php[/i] isn't being found, and I suspect that's because I'm not properly linking the file into my main [i]index.php[/i] file. Is there a better way?

[code]
<?php
    include($_SERVER['DOCUMENT_ROOT'] . "/demos/scripts/browserdetect.php");
    $browsername = browser_detection(browser);
    print '>link rel="Stylesheet" href="rgstyle_' . $browsername . '"<';
?>
[/code]
(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 [i]that[/i] 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

[code]
include("/demos/scripts/browserdetect.php");
[/code]
If you want to echo a string that contains HTML tags, use the function htmlentities() when you echo the string. For example:
[code]<?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.
?>[/code]

Ken
Sadly, neither suggestion has worked.

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

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?
[!--quoteo(post=371031:date=May 3 2006, 03:30 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 3 2006, 03:30 PM) [snapback]371031[/snapback][/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.
[!--quoteo(post=371052:date=May 3 2006, 04:32 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 3 2006, 04:32 PM) [snapback]371052[/snapback][/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
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.
[!--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
[code]<?php include('./scripts/browserdetect.php') ?>[/code]
or
[code]<?php include('scripts/browserdetect.php') ?>[/code]
Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.