Jump to content

Creating a file to add to


Dr Ben Warne

Recommended Posts

So far i have this code


<?php
  session_start();
  if (!isset($_POST['submit'])) {
    echo "<form method='post'>";
    echo "  your name?<input type='text' name='uname'>";
    echo "  <input type='submit' name='submit'>";
    echo "</form>";
  } else {
    $_SESSION['uname'] = $_POST['uname'];
    echo "Welcome {$_SESSION['uname']}, your session id is ". session_id();
  }
?>


But from that i want to, on entry, create a text file that will put the session id into it to wait for another id to join

BUT i want it to search to see whether the file exists (to see if someone is already waiting) the go to a new screen

I have this code previously

$file = fopen("count.txt", "r+");
$count = fread($file, filesize("count.txt"));
fclose($file);
$count += 1;
$file = fopen("count.txt", "w+");
fputs($file, $count);
fclose($file);
echo "You are visitor $count";

That writes to a text file, but i cant adapt it. Any help would be greatly appretiated!

Ben
Link to comment
https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/
Share on other sites

[quote author=kenrbnsn link=topic=117595.msg480066#msg480066 date=1165441352]
Take a look at the function [url=http://www.php.net/file_exists]file_exists()[/url].

You should test that the file exists before writing to it...

Ken
[/quote]

How do i get it to create a new file and put the session id in though?
[quote author=Qtix link=topic=117595.msg481025#msg481025 date=1165575298]
for what do you want to use it?
cause its best to avoid fopen and fwrite
[/quote]

What i want it for one person to get a session id, and then for someone else to aswell so i can pass an array between the 2 users

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.