What am i doing wrong? :-(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

What am i doing wrong? :-(

Post by hob_goblin »

Code: Select all

<?PHP
if(isset($screenname))&#123;
$TheFile = "sn.txt";
$Open = fopen ($TheFile, "a+");
$replaceit = fread($Open, filesize ($TheFile));
$replaceit_2 = ereg_replace("$screenname", "", $replaceit);
fwrite($Open, "$replaceit_2");
fwrite($Open, "$screenname");
fclose ($Open);
&#125;
include("sn.txt");
?>
what is wrong with this code? i want it to log the "screenname" var in a text file, but i want it to check if its there already, and if it is, i dont want it to write it over again...

its probably something stupid, but what can i say, i've only been learning for like a week :oops:
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

anybody?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Are you sure you've CHMOD'd the file to 666? If not, do so.
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

i chmoded it to 777, but the problem im having is it keeps writing the name in, even if its already in there
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Try to CHMOD it to 666, and re-run the program, and see if it works.
Image Image
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

Code: Select all

<?
$array = file('sn.txt');
if(!in_array("$screenname
", $array)) &#123;
  put it there;
&#125;
?>
chmoding to 666 shouldn't make a difference if he already set 777
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

my method is assuming your text file looks like

----------------
blah
blah
blah
name
blah
blah
----------------
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

ok i got it to work, using $HTTP_GET_VARS["var"]

but whenever it logs to the file it writes:

Person'sname HTTP 1.x

any way to change this?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

never mind, i just used ereg_replace :wink:
prasadharischandra
Forum Commoner
Posts: 57
Joined: Thu May 09, 2002 2:19 am
Location: sri lanka
Contact:

Re: What am i doing wrong? :-(

Post by prasadharischandra »

u have to use Unlink fuction and replace new text file where u want
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

what??
prasadharischandra
Forum Commoner
Posts: 57
Joined: Thu May 09, 2002 2:19 am
Location: sri lanka
Contact:

Post by prasadharischandra »

:D
Post Reply