473,748 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple news script help

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'>Ne ws data has been written to
file:<br>";
print "<b>$news</b> ";
print "<br>Go <a href='javascrip t:history.back( )'
style='text-decoration: none'>[back]</a> and refresh page to view new
changes.</p>";
} else if ($news == NULL){
print "<p align='left'>Pl ease enter some news
<a href='javascrip t:history.back( )' style='text-decoration:
none'>[back]</a></p>";
} else {
print "<p align='left'><f ont size='2' face='Arial'>An error
has occurred, news must be at least 4 chars and less than
$max.</font></p>";
}
} else {
print "<b>$passwo rd</b> was not accepted as a password <a
href='javascrip t:history.back( )' style='text-decoration:
none'>[back]</a><br>";
}
}
?>
<html>

<head>
<meta name="GENERATOR " content="Micros oft FrontPage 5.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<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><fon t face="Arial"
size="2">: </font>
<font face="Arial" size="1">(<?php global $max; print $max; ?> chars
max)</font><font face="Arial" size="2"><br><b r>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_SEL F"); ?>>
<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;<in put
type="hidden" name="x" size="1"
value="1">&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&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.t xt");?>
</body>
Jul 16 '05 #1
2 5298
"Cergon" <ce****@bigfoot .com> wrote in message
news:ba******** *************** ***@posting.goo gle.com...
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*******@scrip tsmiths.com
Web: http://www.scriptsmiths.com
---------------------------------------------------------------------------

[snip]
Jul 16 '05 #2
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*******@scri ptsmiths.com> wrote in message news:<3f******* *****@hades.is. co.za>...
"Cergon" <ce****@bigfoot .com> wrote in message
news:ba******** *************** ***@posting.goo gle.com...
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*******@scrip tsmiths.com
Web: http://www.scriptsmiths.com
---------------------------------------------------------------------------

[snip]

Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11294
by: Gelo Ilzi | last post by:
I'm trying to implement a very simple http server with cgi functionality. The code is simple: import CGIHTTPServer, BaseHTTPServer httpd = BaseHTTPServer.HTTPServer(('',8000), CGIHTTPServer.CGIHTTPRequestHandler) httpd.serve_forever() I've created a subdir 'cgi-bin' which contains a python script. Now when I enter this directory, i.e., go to the url http://localhost:8000/cgi-bin/ my
3
2321
by: Alan Clark | last post by:
Dear All I need to do something very simple with Javascript and have been looking all over the web for two days for a suitable script. I'm the kind of person who learns by seeing how it's done. I am a real beginner in programming. I am making a baking recipe site. For each section, say cookies, I will have around 100 recipes, which will be named sequentially, 001.html - 100.html for example.
3
2323
by: Lodewijk van Haringhal | last post by:
I'am new with javascritping not with programming. Is there nobody who can help me with ths simple promblem? :) Please, please give me a hint. Please help me with this script. I have two lists in my form. One to choose a directory and one to choose a picture. The script bellow works perfect without the directory choose function. I tried to make the directory choose function myself but I did not succeed. I think I made a mistake here:...
1
6027
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to be played with - this is not the final result so please (unless it's leading to the script failure)...
13
2366
by: LRW | last post by:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected. Here's what I have: function checkdel() { if (document.getElementById"].value=='1') { confirm('Are you sure you want to delete this file?'); } } ......
9
2124
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE and Safari, but in the latest FireFox I get no title or article, but do see the prev and next links and the article number. My HTML and JS simple routine is as follows:
9
12336
by: Pete | last post by:
Does anyone have a simple html vbscript or other type of snippet they can share that appends a record to a access database via ADO or DAO? I would like to allow users that don't have Microsoft Access a way of adding records to a access database from a simple web page. I don't want to have to setup ODBC or anything like that I just want to put the web page on the network for anyone to access. Most of the users would use the local access...
7
1153
by: SL | last post by:
Could someone direct to a simple explanation of how to use MS Visual Studio 2003 to design .aspx code? This code works if pasted into notepad and run as an .aspx file: <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <script language="vb" runat="server"> Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Dim objConnection As OleDBConnection Dim objCommand As OleDBDataAdapter
24
6341
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.