Page: 1, 2  Next

Problem with Full Featured Browser Detection PHP Script
Dave
Status: Curious
Joined: 09 Aug 2004
Posts: 6
Reply Quote
Hi everyone.

I wanted to test your [new user link] PHP Script but I have some problems with it.

I copy and paste the text from the download and saved a file called test.php where you code is in.

Then I uploaded the test.php but when I start it, i only get a blank a white monitor.

Can you please tell what I have done wrong?

Thx
Back to top
Code needs to run as php include, call it with function
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hi, and welcome to our forums. The script you downloaded is a library file, and doesn't do anything on its own, you have to call that function wherever you need it to get the browser information.

It's designed to be an include for a web page.

Let's leave the name the same as it is on the original to avoid confustion.

Download the latest version, resave the .txt file to the name:

browser_detection.php

Upload this file to your server, to an include file directory if you have that set up already.

On your page, you would bring in that include like this:

<?php include('browser_detection.php'); ?>

to use it, you call the function, you cannot call the function until after you have included the script, with the parameters you want to use, let's say you want to know the browser.

If you don't want to deal with includes, you can paste the script directly onto your webpage, but that's usually not a good idea, it makes it too hard to read the page code.

Either way the script has to be included before the function call that uses it occurs on the page or you will get a php error.

<?php $browser = browser_detection( 'browser'); ?>
<html>
<head>.......

</head>
<body>

then to use that information, just do something like this:

<?php echo $browser; ?>
</body>
</html>

To learn more about setting include paths, read this thread. That's usually the most confusing thing when learning how to use includes.
Back to top
Dave
Status: Curious
Joined: 09 Aug 2004
Posts: 6
Reply Quote
Thanks for your answer.

I send a note to my webhoster and they told me, they will not insert any include Path in the .htaccess due to security reasons.

They told me, I should insert a absolut path to my script.

Sorry, but my english and php is not well. Can you also help me?

Thx
Back to top
PHP server document root, new hoster
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
To solve your problem you'll need to keep your include folder in your website root directory, the same one your index.html or index.php is located in.

To get the absolute path for the include path do this:

<?php
$absolute_path = $_SERVER['DOCUMENT_ROOT'];
$include_path = $absolute_path . '/includes';

include( $include_path . 'browser_detection.php' );

?>

Sorry to take so long to answer, we've been busy here.

For the long term, it would be worth thinking about getting a real webhoster, that gives you more control over your site and programming and apache.
Back to top
Dave
Status: Curious
Joined: 09 Aug 2004
Posts: 6
Reply Quote
Hello jeffd.

Thx for your help, but it is still not working.

Can you explain it once again from the beginning maybe with all steps I have to do.

My first step is to download the latest version, resave the .txt file to the name:

browser_detection.php

I uploaded this file to my root directory I get access on my webserver from my hoster.

What now?

Thx in advance.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
These are the steps I think should work for you.

First of all make sure you have php support on. To do this create a simple html file with this alone in it

:: Code ::
<?php echo 'hello world'; ?>


save it as test.php, upload it to your server, run it by typing in that url, like www.yourdomain.com/test.php

You should see only the words 'hello world' on the screen. If that's all you see, you have PHP, so we can go the next steps.

Take the file 'browser_detection.php' and place it into your includes folder.

Your folder should be here, at the root:

-includes
---browser_detection.php
-other-site-folders
index.html
browser_test_page.php

let's say you are going to use it on the page browser_test_page.php.

the first thing you will do is request the include file, like this:

this will load the script in the server when the page is requested, and it will be ready to use elsewhere on the page

:: Code ::

<?php
$absolute_path = $_SERVER['DOCUMENT_ROOT'];
$include_path = $absolute_path . '/includes/';
include( $include_path . 'browser_detection.php' );
?>
<html>
<head>
<title>your testpage</title>
</head>
<body>

<p>now try and see if the following test works: <br>
Your browser is:
<?php
$browser = browser_detection('browser');
echo $browser;
?>
</p>
</body></html>


If it all works, and if you are using for example Internet Explorer, you should see this alone on the page:

:: Code ::
now try and see if the following test works:
Your browser is: ie


After that you can try playing around with more complicated things.

However, we used to use bad web hosters that always caused us problems like you are experiencing, and we finally realized it was better to have no problems and be able to do everything we wanted with PHP and PERL. And once we switched to a real webhoster, we use Pair.com only, we stopped having any problems.
Back to top
Dave
Status: Curious
Joined: 09 Aug 2004
Posts: 6
Reply Quote
Hello jeffd.

Thx for your help. It´s now working.

But I have also one problem:

Now I´d like to get all information I can get with the help of your script browser_detection.php

Can you please give me the code I need in my browser_test_page.php to get which_os and all information I can get of your script.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Dave, glad to see you got it working. There is a sample script on the php browser detection page available in 'your computer information' box. That is a simplified version that uses the return full features array instead of individual browser information components.

The cookie section of that script requires the javascript cookies script to run, but if you don't want the cookies part you can just delete that part of the script.

Arrays are slightly more confusing if you are not familiar with php, or programming in general, but are much more powerful and efficient.
Back to top
Dave
Status: Curious
Joined: 09 Aug 2004
Posts: 6
Reply Quote
Thanks for your help.

But I have also some Problems:

I insert your "Script Name: Your Computer Information" in my test.html and it looks this way:

<edit cut out code sample to keep it shorter >

What have I done wrong?

Can you maybe give some step by step detail?

Thx
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
I cut and pasted in exactly what you posted and it ran fine, there are some html problems, but nothing that kept it from running.

My suspicion is that you somehow cut off the opening <?php by accident.

But, again, the code sample you posted worked perfectly when I cut it out and ran it.

the only thing I can think of is that your hoster is not allowing you to run php on webpages with html extensions.

Try changing the page extension to .php and see if it runs.

To run php with .htm or .html extensions, read this thread.

However, it sounds like your webhoster may not let you use .htaccess files, but you can always try. Or just name the file browser_test.php and see if it works then.

Also, you had the script come after

</body>

</html>

then you had another
</head>

<body>

</body>

</html>
after the script, most browsers will let you do that without crashing the page, but they shouldn't. The script should be put in between the <body> and </body> tags, with standard html structure.
Back to top
Display posts from previous:   
Page: 1, 2  Next
All times are GMT - 8 Hours