Page 1 of 1
IIS problems with php files
Posted: Fri Sep 17, 2004 8:51 am
by nikola_ns
Hi,
My name is Nikola.
I install IIS for windowsXP, and php installer that configure IIS for use with php. I make vote system but on my computer php don't write into the files.
Vote system that I made is based on two files ip.txt and pool.txt. Ip.txt remembers IP adreses from users taht vote and pool.txt remembers number of answers. On my computer php wan't write in to the pool.txt and ip.txt but when I upload that everything works OK. Can somebody help me.
This last for a long time.
Which interpretter I can use for .cgi files under WindowsXP? And of course witht taht interpretter it should worh with IIS and Internet Explorer.
Nikola[/b]
Posted: Sun Sep 26, 2004 9:48 am
by feyd
first question, why not use a database?
to help you with this, we'll need to see your code, at the least.
code problems???? or not!!
Posted: Mon Sep 27, 2004 1:27 pm
by nikola_ns
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Code: Select all
<HTML><HEAD>
<TITLE>[ ZAVICAJNI MUZEJ PRIBOJ ]</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META http-equiv=description
content="Zavicajni muzej Priboj.">
</HEAD>
<?php
// DEFINE THE VARIABLES //
// title of this poll
//$title = "Da li je našem sajtu potrebna SQL baza podataka?";
// closing date for this poll in MM/DD/YYYY format
$closingDate = "1/1/2010";
// text file that stores vote choices and totals
$pollFile = "poll.txt";
// text file that stores IP addresses
$ipFile = "ips.txt";
// full path to your CSS style sheet
$styleSheet = "glasaj.css"; // leave blank if you aren't using this
// add the user's vote
function is_closed() {
global $closingDate;
// split the closing date into month, day, and year
$closingDate = explode("/", $closingDate);
// get today's today to test against the closing date
$today = getdate();
$message = date("l, F j", mktime(0,0,0,$closingDate[0],$closingDate[1],$today[year]));
// if today's year is greater than the closing year, return true
if ($today[year] > $closingDate[2]) {
return $message;
}
// if today's year is equal to the closing year
elseif ($today[year] == $closingDate[2]) {
// if today's month is greater than the closing month, return true
if ($today[mon] > $closingDate[0]) {
return $message;
}
// if today's month is equal to the closing month
elseif ($today[mon] == $closingDate[0]) {
// if today is greater than or equal to the closing day, return true
if ($today[mday] >= $closingDate[1]) {
return $message;
}
// if the poll is still open, return false
else {
return false;
}
}
// if the poll is still open, return false
else {
return false;
}
}
// if the poll is still open, return false
else {
return false;
}
}
// check if the user has already voted
function has_voted() {
global $ipFile;
global $REMOTE_ADDR;
// open the IP address file
$ips = fopen($ipFile, "r");
// compare each entry with the user's IP address
while (!feof($ips)) {
$ip = fgets($ips, 20);
if ($ip == $REMOTE_ADDR . "\r\n") {
$match = 1;
break;
}
}
// close the IP address file
fclose($ips);
if (!$match) {
// reopen the IP address file
$ips = fopen($ipFile, "a");
// add the user's IP address
fputs($ips, $REMOTE_ADDR . "\r\n");
// close the IP address file
fclose($ips);
return false;
}
else {
return true;
}
}
// add the user's vote
function addVote($vote) {
global $pollFile;
// get the current votes
$fp_read = fopen($pollFile, "r");
$currentVote = fread($fp_read, filesize($pollFile));
fclose($fp_read);
// create an array with even numbers containing vote choices
// and odds containing vote totals
$votes = split('[|:]', $currentVote);
// update the vote
for ($i = 1; $i < count($votes); $i = $i + 2) {
// get the array index number for the name of this vote
$name = $i - 1;
// if this vote choice is this user's selection, increment it
if ($votes[$name] == $vote) {
$votes[$i]++;
}
// if this vote IS the last choice
if ($i == (count($votes) - 1)) {
$updatedVote .= $votes[$name] . ":" . $votes[$i];
}
// if this vote is NOT the last choice
else {
$updatedVote .= $votes[$name] . ":" . $votes[$i] . "|";
}
}
// save the updated vote
$fp_write = fopen($pollFile, "w");
fputs($fp_write, $updatedVote);
fclose($fp_write);
}
// display the poll
function displayPoll($message) {
global $title, $pollFile, $styleSheet;
echo "<html>\n";
echo "<head>\n";
//echo "<title>$title</title>\n";
echo "<link rel="stylesheet" type="text/css" href="$styleSheet" charset=windows-1251>\n";
echo "</head>\n\n";
echo "<body bgcolor=#eff1f6 leftmargin=0 topmargin=0>";
// get the current votes
$fp_read = fopen($pollFile, "r");
$currentVote = fread($fp_read, filesize($pollFile));
fclose($fp_read);
// create an array with even numbers containing vote choices
// and odds containing vote totals
$votes = split('[|:]', $currentVote);
// if a message was sent, print it
if (isset($message)) {
echo "<p align=left>$message</p>\n\n";
}
echo "<table align=center width=216 height=130 bgcolor=#eff1f6 border=0 cellspacing=0 cellpadding=0>";
echo "\t<td align=center bgcolor=#eff1f6><font size=1 face=Geneva, Arial, Helvetica, sans-serif><tr width=216 align=left><font size=1 face=Geneva, Arial, Helvetica, sans-serif></tr></td>\n\n";
// print the poll table rows
// including vote choice, vote total, and percentage of total votes
for ($i = 1; $i < count($votes); $i = $i + 2)
{
// add together each vote total to find the total number of votes cast
$totalVotes += $votes[$i];
}
for ($i = 1; $i < count($votes); $i = $i + 2) {
// get the array index number for the name of this vote
$name = $i - 1;
// calculate the percentage of total votes for this vote
// rounded to 1 decimal place
if ($totalVotes == 0) {
$percentage = 0;
}
else {
$percentage = $votes[$i] / $totalVotes * 100;
$percentage = round($percentage, 1);
}
//if ($percentage == 0) {
echo "<br><tr><td align=center valign=middle width=34% height=130 bgcolor=#eff1f6><tr algin=center><font size=1 face=Geneva, Arial, Helvetica, sans-serif><tr algin=center>$votes[$name] $votes[$i] ($percentage%) <tr><img src=levo.gif height=8><img src=sredina.gif width=$percentage height=8 $percentage%><img src=desno.gif height=8></votes>\n\n";
}
echo "<tr><b>Укупно гласова: $totalVotes\n";
echo "</table>\n";
echo "</body>\n";
echo "</html>\n";
}
// PROGRAM CODE //
// if the poll is closed, display the poll and exit
if ($message = is_closed()) {
displayPoll("Гласање је затворено." . $message . ".");
exit;
}
// if the user is not voting, display the poll and exit
if (!isset($vote)) {
displayPoll("");
exit;
}
// if the user has already voted, display the poll and exit
//if (has_voted()) {
//displayPoll("Âåž ñòå ãëàñàëè.");
//exit;
//}
// add the user's vote
addVote($vote);
// display the poll
displayPoll("");
?>
<title>Rezultati</title>
<style type="text/css">
<!--
-->
</style>
<link href="glasaj.css" rel="stylesheet" type="text/css">
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Mon Sep 27, 2004 1:31 pm
by nikola_ns
This is code form php file.
I use simple post method in html document.
Something like this
<form action=post src=glasajrez.php target_=self>
//radio butons in here with choices
</form>
If you don't understand some words it becouse they are wrote in Serbian langugae.
I'm waiting for your answer.
Nikola
Posted: Mon Sep 27, 2004 1:40 pm
by feyd
from what I've seen, Windows machines require additional modifiers for fopen, namely a 't' or 'b' for text mode or binary mode at the end of the modifiers string.. so using 'at' or 'ab' on line 86 and 136 could fix it.. also, your poll file, is being opened with 'w', this will truncate the file to zero bytes each time it's opened. Is that what you want?
Posted: Mon Sep 27, 2004 2:21 pm
by nikola_ns
I am not sure that I understand you evrything.
So like this:
I open my pool.txt file manulay on my computer and give it number naswers like this:
Yes : 100| No:200| etc.
In browser when I click vote on a button I go to this page with this code and the results, same as I wrote in pool.txt file, but it shuld bee one vote more if I said Yes:, the old number is 100 and the new should 101. Is that OK?
But this is not hapening.
I understand what you had wrote. Like this give my your mail and I will send you whole vote system I than you try it on your computer, but without useing of upload to internet.
CHMOD for pool.txt and ips.txt should be 777.
I am sory if I make some mistakes with english.
Posted: Mon Sep 27, 2004 2:36 pm
by feyd
okay, I see what you were doing now with that part, however, the text and binary mode advice stands.