Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-01-24, 04:15 AM
Junior Member
 
Join Date: Jan 2004
Posts: 4
KhunJack
Default

Dear All,
with help of this forum and google search I puzzeled this Page together.
It collects the Browser information ..writes it off and redirects to the "main" page.

It works perfect on my Windows Box with Apache 1.39, PHP 4.3.3, MySQL 4.x

But I moved it over to my hosting environment and getting the following error:

=================================
Warning: session_register(): Cannot send session cookie - headers already sent by (output started at /home/khunjack/public_html/index.php:9) in /home/khunjack/public_html/index.php on line 76

Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at /home/khunjack/public_html/index.php:9) in /home/khunjack/public_html/index.php on line 76

Warning: Cannot modify header information - headers already sent by (output started at /home/khunjack/public_html/index.php:9) in /home/khunjack/public_html/index.php on line 87
=================================

My index.php looks like .. pls.see below

-------------------------------------------------------------
<?php
// File Location: /index.php
require_once("class.visitors.php");
?>
<html>
<head>
<script language="Javascript" type="text/javascript">
<!--
function getbrowserinfo()
{
var agt=navigator.userAgent.toLowerCase();
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
(agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));
var is_ie = (agt.indexOf("msie") != -1);
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_aol = (agt.indexOf("aol") != -1);
var is_aol3 = (is_aol && is_ie3);
var is_aol4 = (is_aol && is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);

if (is_nav4up) {
this.browser = "Netscape"; // netscape 4+ but not NS5
}else if (is_webtv) { // Web TV
this.browser = "Webtv";
}else if (is_aol || is_aol3 || is_aol4) { //AOL
this.browser = "AOL";
}else if (is_opera) { // Opera
this.browser = "Opera";
}else if (is_ie3||is_nav3) { // 3.0 version browsers
this.browser = "Version3Browser";
}else if (is_ie4up) { //IE4 & IE5 but returns IE4
this.browser = "Microsoft Internet Explorer";
}else if (is_nav5up) { // Netscape 5
this.browser = "Netscape";
}


document.browser_form.browser.value=this.browser;
document.browser_form.screenHeight.value=screen.he ight;
document.browser_form.screenWidth.value=screen.wid th;
document.browser_form.appName.value=navigator.appN ame;
document.browser_form.appCodeName.value=navigator. appCodeName;
document.browser_form.appVersion.value=navigator.a ppVersion.substring(0,4);
document.browser_form.platform.value=navigator.pla tform;
document.browser_form.javaOn.value=navigator.javaE nabled();
document.browser_form.submit();
}
-->
</script>
</head>
<?php
if (isset($browser))
{
// count the vistors and store browser information!!!!!!!
// iniate ...should be on every page !!! ????
$oVisitors = new visitors;
session_register("visitor_info");
$aArgs["javaon"] = $javaOn;
$aArgs["platform"] = $platform;
$aArgs["screenheight"] = $screenHeight;
$aArgs["screenwidth"] = $screenWidth;
$aArgs["browser"] = $browser;
$aArgs["appVersion"] = $appVersion;
$aArgs["id"] = $visitor_info->home[id];
$visitor_info->home[id] = $oVisitors->handleVisitor($aArgs);

// Go to start page
header("Location: site/main/");

}
else
{
echo "<body onload=\"getbrowserinfo()\">\n";
}
?>
<form action="<?php echo $PHP_SELF; ?>" method="post" name="browser_form">
<input type="hidden" name="screenWidth">
<input type="hidden" name="screenHeight">
<input type="hidden" name="appName">
<input type="hidden" name="appCodeName">
<input type="hidden" name="appVersion">
<input type="hidden" name="platform">
<input type="hidden" name="javaOn">
<input type="hidden" name="browser">
</form>
</body>
</html>
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-02-03, 03:37 AM
Junior Member
 
Join Date: Feb 2004
Posts: 4
zara
Default

Hi KhunJack,

you're mixing client-side JavaScript with server-side PHP: That's always a problem especially in the way you are doing.

In this case you are starting output with

"<html>
<head>
<script language="Javascript" type="text/javascript">
...
"

but after that you are using session_register

"
// iniate ...should be on every page !!! ????
$oVisitors = new visitors;
session_register("visitor_info");
$aArgs["javaon"] = $javaOn;
...
"

and that's the main problem: You can only send headers [that's what 'session_register' does] if you DIDN'T START OUTPUT BEFORE.

My suggestion for a solution:
----------------------------
:huh: 1. Have a look at http://www.garykeith.com/ and read the PHP-manual concerning 'browsecap.ini'. PHP uses browscap.ini in their get_browser() function and Gary is their official source for that file. You can then get browser-info via PHP!

-or-

2. Try this:

-------------------------------------------------

<?
if ($_POST) {
echo "<table border=1>";
foreach ($_POST as $key=>$value) {
echo "<td>$key</td><td>$value</td></tr>\n";
}
echo "</table>";
exit;
}
?>
<html>
<body>
<form action="<?php echo $PHP_SELF; ?>" method="POST" name="browser_form">
<input type="hidden" name="screenWidth">

<input type="hidden" name="screenHeight">

<input type="hidden" name="appName">

<input type="hidden" name="appCodeName">

<input type="hidden" name="appVersion">

<input type="hidden" name="platform">

<input type="hidden" name="javaOn">

<input type="hidden" name="browser">

</form>
<script language="JavaScript">
function GetBrowserInfo() {
var agt=navigator.userAgent.toLowerCase();
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));
var is_ie = (agt.indexOf("msie") != -1);
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_aol = (agt.indexOf("aol") != -1);
var is_aol3 = (is_aol && is_ie3);
var is_aol4 = (is_aol && is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);
if (is_nav4up) {
this.browser = "Netscape"; // netscape 4+ but not NS5
}else if (is_webtv) { // Web TV
this.browser = "Webtv";
}else if (is_aol || is_aol3 || is_aol4) { //AOL
this.browser = "AOL";
}else if (is_opera) { // Opera
this.browser = "Opera";
}else if (is_ie3||is_nav3) { // 3.0 version browsers
this.browser = "Version3Browser";
}else if (is_ie4up) { //IE4 & IE5 but returns IE4
this.browser = "Microsoft Internet Explorer";
}else if (is_nav5up) { // Netscape 5
this.browser = "Netscape";
}
document.browser_form.browser.value = this.browser;
document.browser_form.screenHeight.value = screen.height;
document.browser_form.screenWidth.value = screen.width;
document.browser_form.appName.value = navigator.appName;
document.browser_form.appCodeName.value = navigator.appCodeName;
document.browser_form.appVersion.value = navigator.appVersion.substring(0,4);
document.browser_form.platform.value = navigator.platform;
document.browser_form.javaOn.value = navigator.javaEnabled();
document.forms["browser_form"].submit();
}
GetBrowserInfo();
</script>
</body>
</html>
-------------------------------------------------
First: understand "my" different way of thinking: I seperated Javascript and PHP completely; that's the only solution I can think of regarding your problem.

hih, zara

:blink: PS: this is my first post in this forum, I'm not sure, wether I receive mail when you -hopefully- reply. If the are any questions or whatever left: grabenhorst@pioneer.de.
Yeah, my english is not native. pls do not mention any mistakes...

bye, zara
Reply With Quote
  #3 (permalink)  
Old 2004-02-03, 03:45 AM
Junior Member
 
Join Date: Feb 2004
Posts: 4
zara
Default

[deleted due to changes in first post]
Reply With Quote
  #4 (permalink)  
Old 2004-02-03, 04:25 AM
Junior Member
 
Join Date: Feb 2004
Posts: 4
zara
Default

Check
http://be.php.net/manual/en/function.get-browser.php

and the following code:

<?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "$key: $value
\n";
}
return $str;
}
echo "$HTTP_USER_AGENT<hr>\n";
$browser = get_browser();
echo list_array ((array) $browser);
?>

bye, zara
Reply With Quote
  #5 (permalink)  
Old 2004-02-03, 06:59 AM
Junior Member
 
Join Date: Jan 2004
Posts: 4
KhunJack
Default

Zara,
thanks a lot .. mhh ..I wasn't aware about the get_browser command ..

Meanwhile I realized another solution.
My first page is having all the java scripts..I move them over to a second page which writes them to the database ..and hopp afterwards of my real "first page"... what you think about this solutions ..any comments?

Al the Best
Jack

------------------------------------
PAge 1..
------------------------------------
<HTML>
<?php
// File Location: /index.php
// Vistats Tracker Test
include("visitor_stats/visitor_stats.php");


require_once("elements.php");
require_once("class.visitors.php");

// iniate
$oVisitors = new visitors;

// ..is the Google Dance on ?
if (@ereg("Google", $agent)) {
$iVisitsCnt = $oVisitors->addGoogleDanced();
}

// Verify if user come from search engine, keep arec incl. search criterions
// this function should be tried to include into the handleVisitor function
// but for testing ... the PAge needs to be listed first
$iVisitsCnt = $oVisitors->addSearchKeywords();
?>
<HEAD>
</HEAD>
<script language="Javascript">
var agt=navigator.userAgent.toLowerCase();
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
(agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));
var is_ie = (agt.indexOf("msie") != -1);
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_aol = (agt.indexOf("aol") != -1);
var is_aol3 = (is_aol && is_ie3);
var is_aol4 = (is_aol && is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);

if (is_nav4up) {
this.browser = "Netscape"; // netscape 4+ but not NS5
}else if (is_webtv) { // Web TV
this.browser = "Webtv";
}else if (is_aol || is_aol3 || is_aol4) { //AOL
this.browser = "AOL";
}else if (is_opera) { // Opera
this.browser = "Opera";
}else if (is_ie3||is_nav3) { // 3.0 version browsers
this.browser = "Version3Browser";
}else if (is_ie4up) { //IE4 & IE5 but returns IE4
this.browser = "Microsoft Internet Explorer";
}else if (is_nav5up) { // Netscape 5
this.browser = "Netscape";
}


sB=this.browser;
sSH=screen.height;
sSW=screen.width;
sAV=navigator.appVersion.substring(0,4);
sP=navigator.platform;
sJ=navigator.javaEnabled();
redi_str = "index2.php?sJ="+sJ+'&sB='+sB+'&sAV='+sAV+'&sSH='+ sSH+'&sSW='+sSW+'&sP='+sP;
location = redi_str;
//-->
</script>
</HTML>


------------------------------------
Page 2...
-------------------------------------
<?php
// File Location: /index2.php
// session start
session_start();
require_once("elements.php");
require_once("class.visitors.php");


if(isset($_GET['sJ'])) {
// count the vistors and store browser information!!!!!!!
// iniate ...should be on every page !!! ????
$oVisitors = new visitors;
// $_SESSION["visitor_info"];
session_register("visitor_info");
$aArgs["javaon"] = $_GET['sJ'];
$aArgs["platform"] = $_GET['sP'];
$aArgs["screenheight"] = $_GET['sSH'];
$aArgs["screenwidth"] = $_GET['sSW'];
$aArgs["browser"] = $_GET['sB'];
$aArgs["appVersion"] = $_GET['sAV'];
$aArgs["id"] = $visitor_info->home[id];
$visitor_info->home[id] = $oVisitors->handleVisitor($aArgs);
// Let's visit the pages
header("Location: /site/main/index.php");
} else {

print "Ohhhh No";
}

// und das eben mit allen varianten

?>
Reply With Quote
  #6 (permalink)  
Old 2004-02-03, 08:06 AM
Junior Member
 
Join Date: Feb 2004
Posts: 4
zara
Default

Yep. I think that's fine:

page1----------------------
if (session_is_open) {
...
} else {
do JavaScript
call page2 via form.submit
}

page2----------------------
write JS_Data_2_Database
open session
call page1

#############################
I prefer doing all stuff like this in one single file, but that's my personal point of view. Refering to my suggestion I mean:

pageN-------------------------

<?
# NO OUTPUT LIKE HTML, ECHO, etc. before this!
if (session_is_open) {
OUTPUT LIKE HTML, ECHO, etc. starts here
...
do whatever_you_want
...
} elseif (js_is_done) {
# NO OUTPUT LIKE HTML, ECHO, etc.
write JS_Data_2_Database
open session
call pageN
} elseif {
?>
JavaScript goes here...
call pageN via form.submit
<?
}
?>

by the way: consider using 'header("Location: page_xyz.php")' instead of 'document.location'.
What do you do, if your client hasn't activated JS?
In fact, I think the get_browser-command is much saver and will lead to the most accurate results...
beside this I think it's much easier then "our" approach.

bye, zara

you are german, aren't you? that's what I am...
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:09 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.