Article View: be.comp.programming
Article #7223php probleem
From: Coppieters-Driessen
Date: Thu, 10 Oct 2002 16:43
Date: Thu, 10 Oct 2002 16:43
154 lines
5416 bytes
5416 bytes
Hoi,
wie kan mij helpen met onderstaand script "game_dispenser.php"?
Probleem:
1- functie "clean old files" werkt niet, krijgt volgende foutcode. Warning:
unlink() failed (Is a directory) in /home/www1host/public_html/mijn
link/cgi-bin/game_dispenser.php on line 76.
Warning: cannot add header information - headers already sent by (output
started at /home/www1host/public_html/mijn
link/cgi-bin/game_dispenser.php:76)in/home/www1host/public_html/yannick/cgi-
bin/game_dispenser.php on line 116
directory bestaat als volgt.
root/cgi-bin/game_dispenser.php
root/cgi-bin/sk_sessions/...txt files die het script aangemaakt heeft.
2- functie "prepare cookie" werkt ook niet. Script maakt geen cookie aan op
mijn pc. Mijn brouwser was tijdens controle niet afgesloten.
Kan iemand eventueel het script aanpassen?
Groetjes.
Het script.
# INSTRUCTIONS:
#
# The session id folder must be created manually before this script will
# function properly.
#
# Send this script a game location via GET or POST, such as:
#
# game_url=http://www.foo.com/bar/game.html
# Where is your session id folder? This folder will be located relative to
# this script. It must match with the folder location specified in the
# ScoreKeeper script.
$session_id_folder = 'sk_sessions';
# Where are your games located? This should be set as restrictive as
possible.
# If you are certain that all games located on your server are valid, you
may
# simply use 'http:\/\/www.foo.com'. Notice that some of the
meta-characters,
# such as a forward slash, "/", require escaping with a back slash...like
this:
# "\/".
$game_validator = 'http:\/\/www.www1host.net';
#
############################################################################
####
# CLEAN OLD FILES
clean_old_files();
# VALIDATE GAME.
validate_game();
# CREATE ID.
create_id();
# SAVE ID VARIABLES.
save_id_variables();
# PREPARE COOKIE.
prepare_cookie();
# PRINT REDIRECT HEADER.
print_redirect_header();
# WHEW! FINISHED!
exit;
function clean_old_files() {
global $session_id_folder;
# gather up all of the session id filenames
$dr = opendir($session_id_folder) or error("Invalid session id folder.
Failed at line " . __LINE__ . ".");
$files = readdir($dr);
closedir($dr);
# change to session id folder
chdir($session_id_folder);
settype($files, "array");
foreach ($files as $fcheck) {
# look for files that are older than approximately 1 hr and delete
them
if (time()-filemtime($fcheck) > 3600) {
unlink($fcheck);
}
}
}
function validate_game() {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
global $game_url, $game_validator;
$game_url = ($HTTP_POST_VARS['game_url'] ? $HTTP_POST_VARS['game_url'] :
$HTTP_GET_VARS['game_url']);
preg_match('/^' . $game_validator . '.*/', $game_url) or error("Game URL
could not be validated at line " .
__LINE__ . ".");
}
function create_id() {
global $sk_id;
# unique id is made up of 3 parts, separated by underscores:
# 1) process id
# 2) IP address
# 3) number of non-leap seconds since January 1, 1970
$remote_addr = getenv('REMOTE_ADDR');
preg_replace('/\./', '/_/', $remote_addr);
$sk_id = getmypid() . '_' . $remote_addr . '_' . time();
# the ScoreKeeper script is written to accept only alphanumeric ids
}
function save_id_variables() {
global $sk_id;
$fh = fopen($sk_id, "w") or error("Session file could not be opened at
line " . __LINE__ . ".");
# this will save some environmental variables to the session id file
fwrite($fh, getenv('HTTP_USER_AGENT'));
fwrite($fh, "\n");
fwrite($fh, getenv('REMOTE_ADDR'));
fclose($fh);
}
function prepare_cookie() {
global $sk_id;
# cookie values should be as restrictive as possible
# this cookie will expire when the browser closes
# path set as '/' makes the cookie available to all files on your site
setcookie('SK_ID', $sk_id, 0, '/');
}
function print_redirect_header() {
global $game_url;
print '<html><head>';
print '<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=' . $game_url . '">';
print '</html></head>';
}
function error($ouch) {
# something went wrong
print $ouch;
exit;
}
?>
Technical Details
Message-ID:
<F6ip9.155260$8o4.24149@afrodite.telenet-ops.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!iad-peer.news.verio.net!news.verio.net!skynet.be!skynet.be!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,aab45450b1c51585,start X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2002-10-10 09:47:00 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!iad-peer.news.verio.net!news.verio.net!skynet.be!skynet.be!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mail From: "Coppieters-Driessen" <r.coppieters@pandora.be> Newsgroups: be.comp.programming Subject: php probleem Lines: 156 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <F6ip9.155260$8o4.24149@afrodite.telenet-ops.be> Date: Thu, 10 Oct 2002 16:43:17 GMT NNTP-Posting-Host: 213.119.61.86 X-Complaints-To: abuse@telenet.be X-Trace: afrodite.telenet-ops.be 1034268197 213.119.61.86 (Thu, 10 Oct 2002 18:43:17 MET DST) NNTP-Posting-Date: Thu, 10 Oct 2002 18:43:17 MET DST Organization: Telenet Internet