hi there .. I am completely stuck with the following and was hoping if someone could help me there ... i want to do a links-section where u can add your own links to existing links.
to start with i used arrays for the existing links in my flash movie so that i can push additional information easy into it. Currently i am trying to come up with a script that allows me to write the info given by the user (LinkName, LinkURL) to a textfile called subscriber.dat.
from there i wanted to read back the added info and update the info displayed in my flash movie.
the following script is what i came up with but it doesn't work :
<?
if (!isset($linkname) || !isset($linkurl) || empty($linkurl) || empty($linkname)) {fail("Both, name and url, are required");}
$linkname = strtolower($linkname);
$linkurl = strtolower($linkurl);
$subsFile = 'subscriber.dat';
switch($action) {
case "subscribe":
subscribe($linkname, $linkurl);
break;
}
function subscribe($linkname, $linkurl) {
if (isSubscribed($linkurl)) {
fail("$linkurl already exists");
$logEntry="$linkurl already exists");
writeLog($logEntry);
}
$joinDate = time();
$file = fopen('subscriber.dat', 'a+');
if (!$file) {
fail("Error: Couldn't add link")
$logEntry="Error: Couldn't add link");
writeLog($logEntry);
}
fputs($file, "$linkname|$linkurl|$joinDate\n");
fclose($file);
sendEmail($linkname, $linkurl);
success();
}
function sendEmail($linkname, $linkurl) {
$mailTo = "Wolfgang Fruchtl<wolfgang@justsayinghello.com>";
$mailFrom = "From: WWW.JUSTSAYINGHELLO.COM";
$mailSubject = "NEW LINK HAS BEEN ADDED...";
$mailBody = "$linkname, $linkurl\n\nY";
mail($mailTo, $mailSubject, $mailBody, $mailFrom);
}
function isSubscribed($linkurl) {
$matchFound = false;
$subscribers = file('subscriber.dat');
if ($subscribers) {
foreach($subscribers as $count => $subscriber) {
$info = explode('|', $subscriber);
if($info[1] == $linkurl) {
$matchFound = true;
}
}
}
return $matchFound;
}
function fail($errorMsg) {
$errorMsg = urlencode($errorMsg);
print "&result=Fail&errorMsg=$errorMsg";
exit;
}
function success() {
print "&result=Okay";
exit;
}
function fetchList() {
// Register global variables
global $subsFile;
// Attempt to open subscriber file
$subscribers = file($subsFile);
// For each subscriber line...
foreach($subscribers as $count => $subscriber) {
// split subscriber info into array
$info = explode('|', $subscriber);
// Assign array to meaningful variable name
$linkname = $info[0];
$linkurl = $info[1];
$joined = $info[2];
// Create a readable joined date out of timestamp
$joined = strftime("%D", $joined);
// Output information for each subscriber
echo "&newlinkname=" . urlencode($linkname);
echo "&newlinkurl=" . urlencode($linkurl);
echo "&newjoined=" . urlencode($joined);
}
}
function writeLog($logEntry) {
// Filename of log file
$logFile = "error.log";
// Create human readable date/time string for
// current time
$dateStamp = strftime("%D %T", time());
// Open log file for appending
$file = @fopen($logFile, "a");
// If we've opened the file successfully
if ($file) {
// Write the log entry and close file
fwrite($file, "$dateStamp: $logEntry\n");
fclose($file);
// Return success
return true;
} else {
// Otherwise, return failure
return false;
}
}
?>
can anyone help me with this ... PPLLLEEEAAAAASSSEEEEEE