By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

simple news script help

P: n/a
hi, i hope someone can help.
Im pretty new to this php stuff and i have a slight problem. I have
this script (shown below) which writes data to a text file which is
then displayed on my front page. Trouble is after moving to an apache
server with php on a windows platform the script no longer works. It
worked fine on the unix platform. All it does now is just wipes the
text file and does not write anyhing else to it, any help would be
much appreciated.

<?php
/////////////////////////////////////////////////////////////////////////
/////////////////////////////set the
following///////////////////////////
/////////////////////////////////////////////////////////////////////////
$max = "730"; // sets the maximum amount of chars allowed per post.
$urpassword = "PASSWORD"; //set to your desired password.
/////////////////////////////////////////////////////////////////////////
$date_array = getdate();
$time = date("l, d M Y");

if ($x == "1") {
global $urpassword;
if ($password == $urpassword){
global $max;
if ( strlen($news) > 3 and strlen($news) <= $max){
global $news, $time;
$filename = "news.txt";
$fp = fopen( $filename, "w" ) or die ("no file opening is
occuring"); //$fp is short for file pointer
flock($fp,1); //allows file reading but prevents writing
fwrite($fp," ");
rewind($fp); // re-sets file pointer to start of file.
$newsall = "<strong>.:: $time ::.</strong><br><br>$news ";
fwrite( $fp, $newsall); //writes the value of the counter to
where filepointer is.
flock($fp,3); //releases file
print "<p align='left'>News data has been written to
file:<br>";
print "<b>$news</b> ";
print "<br>Go <a href='javascript:history.back()'
style='text-decoration: none'>[back]</a> and refresh page to view new
changes.</p>";
} else if ($news == NULL){
print "<p align='left'>Please enter some news
<a href='javascript:history.back()' style='text-decoration:
none'>[back]</a></p>";
} else {
print "<p align='left'><font size='2' face='Arial'>An error
has occurred, news must be at least 4 chars and less than
$max.</font></p>";
}
} else {
print "<b>$password</b> was not accepted as a password <a
href='javascript:history.back()' style='text-decoration:
none'>[back]</a><br>";
}
}
?>
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Sunk Scripts: Simple News</title>
<style fprolloverstyle>A:hover {color: #000000}
</style>
</head>
<font face="Arial" size="2">Enter a small news bulletin and your
password </font>

</html>
<font face="Arial" size="2">below</font><html><font face="Arial"
size="2">: </font>
<font face="Arial" size="1">(<?php global $max; print $max; ?> chars
max)</font><font face="Arial" size="2"><br><br>Date Stamp: <b><?php
print $time; ?></b></font>
<body text="#000000" link="#000080" vlink="#000080" alink="#000080"
style="font-family: Arial; font-size: 10pt">
<form method="POST" action=<?php print("$PHP_SELF"); ?>>
<p>
<textarea rows="9" name="news" cols="38" style="border-style: solid;
border-width: 1"></textarea><br>
<input type="password" name="password" size="20"
style="border-style: solid; border-width: 1">&nbsp;<input
type="hidden" name="x" size="1"
value="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Submit" name="B1" style="font-family:
Arial; font-size: 10px; background-color: #FFFFFF"><input type="reset"
value="Reset" name="B2" style="font-family: Arial; font-size: 10px;
background-color: #FFFFFF"></p>
</form>

</body></html>
<b>Current Headline:</b><br><?php include("news.txt");?>
</body>
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Cergon" <ce****@bigfoot.com> wrote in message
news:ba**************************@posting.google.c om...
hi, i hope someone can help. [snip]
server with php on a windows platform the script no longer works. It
worked fine on the unix platform. All it does now is just wipes the
text file and does not write anyhing else to it, any help would be
much appreciated.
[snip]
$fp = fopen( $filename, "w" ) or die ("no file opening is
occuring"); //$fp is short for file pointer
flock($fp,1); //allows file reading but prevents writing
fwrite($fp," ");

At a very brief glance, I would be suspect of the flock(...)

I am not 100% of PHPs implementation on Windows, but I do know that the
flock() call from Perl is not supported on Windows. Windows doesn't
supporting
file locking through a system call flock(), unix/linux does.

In Perl scripts, one has to take the flock() out and use some other
flakey/shaky
method of file locking. Perhaps thats the problem here?

Thanks,
Mark
---------------------------------------------------------------------------
Windows, Linux and Internet Development Consultant
Email: co*******@scriptsmiths.com
Web: http://www.scriptsmiths.com
---------------------------------------------------------------------------

[snip]
Jul 16 '05 #2

P: n/a
Mark,

Thanks for your response, this makes sense but how could i change my
script so that it works in windows (sorry, im a PHP newbie)

"Mark Hewitt" <co*******@scriptsmiths.com> wrote in message news:<3f************@hades.is.co.za>...
"Cergon" <ce****@bigfoot.com> wrote in message
news:ba**************************@posting.google.c om...
hi, i hope someone can help.

[snip]
server with php on a windows platform the script no longer works. It
worked fine on the unix platform. All it does now is just wipes the
text file and does not write anyhing else to it, any help would be
much appreciated.


[snip]
$fp = fopen( $filename, "w" ) or die ("no file opening is
occuring"); //$fp is short for file pointer
flock($fp,1); //allows file reading but prevents writing
fwrite($fp," ");

At a very brief glance, I would be suspect of the flock(...)

I am not 100% of PHPs implementation on Windows, but I do know that the
flock() call from Perl is not supported on Windows. Windows doesn't
supporting
file locking through a system call flock(), unix/linux does.

In Perl scripts, one has to take the flock() out and use some other
flakey/shaky
method of file locking. Perhaps thats the problem here?

Thanks,
Mark
---------------------------------------------------------------------------
Windows, Linux and Internet Development Consultant
Email: co*******@scriptsmiths.com
Web: http://www.scriptsmiths.com
---------------------------------------------------------------------------

[snip]

Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.