Tagwall i PHP
Hejsa.Jeg er ikke så god til PHP, og jeg har prøvet med den "lav selv" tagwall. Når jeg prøver at kører PHP filen får jeg bare en blank side....
Link : http://www.stoltenborg.info/twall/tagwall.class.php
Kode :
class Tagwall {
var $ERRORS;
var $txtfile;
var $dbinfo = array();
var $method = 0;
/**
* This function sets the file where tagwall data will be saved
* REMEMBER TO GIVE THIS FILE WRITE PERMISSION (chmod 777)
*
* @param $file name of text file to save tagwall info
*/
function setFile($file) {
$this->txtfile = $file;
}
/**
* This function sets the database info for the tagwall data
*
* @param $server hostname of mySQL server
* @param $pass password for mySQL database
* @param $user mySQL username
* @param $db name of the database for the tagwall
*/
function setDBInfo($server, $user, $pass, $db) {
$this->dbinfo = array("localhost" => $server,
"stoltenborg" => $user,
"password" => $pass,
"wall" => $db);
}
/**
* This function selects which method to access tagwall data
*
* @param $method set this parameter to 0 = use text file, and 1 = use mySQL database
*
* @return boolean true or false
*/
function setMethod($method = 0) {
if ($method == 0 || $method == 1) {
$this->method = $method;
return true;
} else {
$this->ERROR = "Invalid method.";
return false;
}
}
/**
* This function fetches tagwall data with selected method
*
* @return array tagwall entries
*/
function fetchTagwallData() {
if ($this->method == 0) {
$fp = fopen($this->txtfile, "r");
if ($fp) {
$contents = fread($fp, filesize($this->txtfile));
$contents = explode("|", $contents);
foreach ($contents as $key => $value) {
$contents[$key] = unserialize(&$contents[$key]);
if (!empty($contents[$key]["name"])) {
$data[] = $contents[$key];
}
}
$data = array_reverse($data);
fclose($fp);
return $data;
} else {
$this->ERRORS = "Could not open file.";
return false;
}
} else {
$link = mysql_connect($this->dbinfo["localhost"], $this->dbinfo["stoltenborg"], $this->dbinfo["password"]) or die("Could not connect to mySQL");
mysql_select_db($this->dbinfo["wall"], $link);
$result = mysql_query("SELECT * FROM tagwall ORDER BY created_on DESC", $link);
while ($row = mysql_fetch_row($result)) {
$data[] = array("name" => $row["name"],
"email" => $row["email"],
"text" => $row["text"],
"date" => $row["created_on"]);
}
mysql_close($link);
return $data;
}
}
/**
* This function inserts an entry to the tagwall
*
* @param $name name of user
* @param $email users email address
* @param $text text message
*
* @return boolean true or false
*/
function insertTagwallData($name, $email, $text) {
$data = array("name" => $name,
"email" => $email,
"text" => $text,
"date" => time());
$data = serialize($data);
if ($this->method == 0) {
$fp = fopen($this->txtfile, "a");
if ($fp) {
$fp = fwrite($fp, $data . "|");
return true;
} else {
$this->ERRORS = "Could not open file.";
return false;
}
} else {
$link = mysql_connect($this->dbinfo["localhost"], $this->dbinfo["stoltenborg"], $this->dbinfo["password"]) or die("Could not connect to mySQL");
mysql_select_db($this->dbinfo["wall"], $link);
mysql_query("INSERT INTO tagwall SET name = '$name', email = '$email', text = '$text', created_on = " . time(), $link);
mysql_close($link);
}
}
}
?>
Min MySql DB kører fint, og den melder ok for login...
//Jan
