Jump to content

[SOLVED] Php Class not working? Was fine while it was procedural script...


Alex-Grim

Recommended Posts

This was just an included script, but i changed it to be oo, and now it's broken. If you take out all the code between the class definitaion, it doesn't stop page execution, but i've tried taking out sections of the code, and no matter what section i remove, it's not allowing the page to execute, so i don't know what it is, i can't see any errors. Here it is:

<?php
class UserVars{
$uagent = $_SERVER['HTTP_USER_AGENT'];

function time(){
	date_default_timezone_set('UTC');
	return date('Y-m-d H-i-s');
}

function agent(){
	return $uagent;
}

function browser(){
	if (ereg("MSIE",$uagent)) {
		$browser = "IE";
	} elseif (ereg( "Opera",$uagent)) {
		$browser = "Opera";
	} elseif(ereg("Firefox",$uagent)) {
		$browser = "Firefox";
	} elseif(ereg("Safari",$uagent)) {
		$browser = "Safari";
	} else {
		$browser= "other";
	}
	return $browser;
}

function os(){
	if (ereg("Win",$uagent)) {
		$os="Win";
	} else if (ereg("Mac",$uagent)) {
		$os="Mac";
	} else if (ereg("Linux",$uagent)) {
		$os="Linux";
	} else if (ereg("Unix",$uagent)) {
		$os="Unix";
	} else {
		$os="Other";
	}
	return $os;
}

funtion dist(){
	if (ereg("Fedora",$uagent)) {
		$distro="Fedora";
	} else if (ereg("Ubuntu",$uagent)) {
		$distro="Ubuntu";
	} else if (ereg("Debian",$uagent)) {
		$distro="Debian";
	} else if (ereg("FreeBSD",$uagent)) {
		$distro="FreeBSD";
	} else if(ereg("NT 4.0",$uagent)) {
		$distro="NT";
	} else if (ereg("NT 5.0",$uagent)) {
		$distro="2000";
	} else if (ereg("NT 5.1",$uagent)) {
		$distro="XP";
	} else if (ereg("NT 5.2",$uagent)) {
		$distro="XP";
	}else if (ereg("NT 6.0",$uagent)) {
		$distro="Vista";
	} else {
		$distro="Other";
	}
	return $distro;
}


function ip(){
	return $_SERVER['REMOTE_ADDR'];
}

function ip2(){
	if ($ip2 = getenv('HTTP_CLIENT_IP')) {}
		elseif ($ip2 = getenv('HTTP_X_FORWARDED_FOR')) {}
		elseif ($ip2 = getenv('HTTP_X_FORWARDED')) {}
		elseif ($ip2 = getenv('HTTP_FORWARDED_FOR')) {}
		elseif ($ip2 = getenv('HTTP_FORWARDED')) {}
		else {
		$ip2 = "0";
	}
	return $ip2;
}
}
?>

Thanx

Link to comment
Share on other sites

<?php

include_once("variables.php");

include_once("../classes/MySql.php");

 

//$uvar = new UserVars();

$db = new MySql();

$con = $db->C();

 

$name = $_POST['name'];

$phone = $_POST['phone'];

$email = $_POST['email'];

$comment = $_POST['comment'];

$uri = str_replace("http://","",$_POST['uri']);

//echo $name . $br;

//echo $phone . $br;

//echo $email . $br;

//echo $comment . $br;

//echo $time . $br;

//echo $ip . $br;

//echo $ip2 . $br;

//echo $uvar->browser . $br;

//echo $uvar->agent . $br;

//echo $uvar->os . $br;

//echo $uvar->dist . $br;

echo $uri . $br;

 

//$q = $db->Q("Insert into Comments (name,phone,email,comment,uri,commentdate,ipaddy,ipforward,useragent,browser,distro,platform)values('$name','$phone','$email','$comment','$uri','$uvar->time','$uvar->ip','$uvar->ip2','$uvar->agent','$uvar->browser','$uvar->dist','$uvar->os')");

?>

Link to comment
Share on other sites

Simply calling the page to be included is where it's being stopped. I have commented out where i tired to instantiate it and use it, to see if merely including it would kill the page, and as you can see, it does, so the error must be in the class file...

 

Even THIS kills it:

<?php

include_once("variables.php");

?>

 

 

===Edit===

And YES, they're in the same directory ;)

Link to comment
Share on other sites

Try this

 

<?php
class UserVars{
var $uagent;
        function UserVars(){
               $uagent = $_SERVER['HTTP_USER_AGENT'];
        }

function time(){
	date_default_timezone_set('UTC');
	return date('Y-m-d H-i-s');
}

function agent(){
	return $uagent;
}

function browser(){
	if (ereg("MSIE",$uagent)) {
		$browser = "IE";
	} else if (ereg( "Opera",$uagent)) {
		$browser = "Opera";
	} else if(ereg("Firefox",$uagent)) {
		$browser = "Firefox";
	} else if(ereg("Safari",$uagent)) {
		$browser = "Safari";
	} else {
		$browser= "other";
	}
	return $browser;
}

function os(){
	if (ereg("Win",$uagent)) {
		$os="Win";
	} else if (ereg("Mac",$uagent)) {
		$os="Mac";
	} else if (ereg("Linux",$uagent)) {
		$os="Linux";
	} else if (ereg("Unix",$uagent)) {
		$os="Unix";
	} else {
		$os="Other";
	}
	return $os;
}

funtion dist(){
	if (ereg("Fedora",$uagent)) {
		$distro="Fedora";
	} else if (ereg("Ubuntu",$uagent)) {
		$distro="Ubuntu";
	} else if (ereg("Debian",$uagent)) {
		$distro="Debian";
	} else if (ereg("FreeBSD",$uagent)) {
		$distro="FreeBSD";
	} else if(ereg("NT 4.0",$uagent)) {
		$distro="NT";
	} else if (ereg("NT 5.0",$uagent)) {
		$distro="2000";
	} else if (ereg("NT 5.1",$uagent)) {
		$distro="XP";
	} else if (ereg("NT 5.2",$uagent)) {
		$distro="XP";
	}else if (ereg("NT 6.0",$uagent)) {
		$distro="Vista";
	} else {
		$distro="Other";
	}
	return $distro;
}


function ip(){
	return $_SERVER['REMOTE_ADDR'];
}

function ip2(){
	if ($ip2 == getenv('HTTP_CLIENT_IP')) {}
		else if ($ip2 == getenv('HTTP_X_FORWARDED_FOR')) {}
		else if ($ip2 == getenv('HTTP_X_FORWARDED')) {}
		else if ($ip2 == getenv('HTTP_FORWARDED_FOR')) {}
		else if ($ip2 == getenv('HTTP_FORWARDED')) {}
		else {
		$ip2 = "0";
	}
	return $ip2;
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.