Login Register


- Paying 994 DZ Points -[Help] Writing to text file via php and overwriting it filter_list
Author
Message
- Paying 994 DZ Points -[Help] Writing to text file via php and overwriting it #1
Well I'm very new to php and have been trying to learn what I stated in the above title ^, I need to figure out how to write to a php via link, example would be "www.message.com/write.php?message=hi this is a test", but every time I write to it it'd over write the existing text in the text file. Does anyone know how I would go about doing this?

Also if you know how to do this without overwriting it, and just adding the next entry to a new line, that'd be awesome!
[Image: OkXCq.gif]

Reply

RE: - Paying 994 DZ Points -[Help] Writing to text file via php and overwriting it #2
Hmm, so you just need to write a string to a file via a link?

Code:
$write = fopen('file', 'a'); fwrite($write, 'This is a test\n');

Not exactly sure if that's what you were looking for as I don't completely understand your request. That's how you'd do it via file, and I'm not sure if PHP File I/O also includes seeking like in Python. If it does, and you want to be at the front of the program you'd do seek(0) or some variation in it with PHP.

You kept saying you were overwriting the file, and this is because when you open up a file with the 'w' or 'w+' permissions, it will automatically truncate all contents within it. Every language has it (Python, PHP, C++, etc). It's an OS problem, not the language itself. If you append the file, it doesn't delete the contents and that's the only way I really get around it.

edit;

If this doesn't work, or doesn't help you at all, please tell me. I'll keep looking into it so I can help you out as I want to know for my own benefit. Surprisingly, I can't get my head wrapped around it, but I'll try my best and research later if the information I've provided isn't beneficial to you at all. Though, it should be in the ballfield, so you may be able to get it done.

Reply

RE: - Paying 994 DZ Points -[Help] Writing to text file via php and overwriting it #3
I already got it from another person but if you still want the points you can have them. PM me if you do.
[Image: OkXCq.gif]

Reply

RE: - Paying 994 DZ Points -[Help] Writing to text file via php and overwriting it #4
Oh alright. Well, glad you got it fixed.

Reply

RE: - Paying 994 DZ Points -[Help] Writing to text file via php and overwriting it #5
Use some $_GET requests.

Something like:
<?php
#######
// By Fhoto, I'm bored k
#######
// File to write to, make sure the permissions are 777
$file_open = './logs.txt'
$message = $_GET['message']
// Use HTTP_CF_CONNECTING_IP -- If you're using Cloudflare
$ip = $_SERVER['REMOTE_ADRR'];
$file_write = 'Message:'.$message.' Sent by: '.$ip';
if(!isset($_GET['message'])) die('Error: Enter a message');
if(isset($_GET['message']))
file_put_contents(string $file_open , mixed $file_write);
?>
[/php]
  • Contact Paradox or Uzi for Admin related duties
  • Contact Operate for Staff queries
  • PM me if you need any help.

Reply







Users browsing this thread: 1 Guest(s)