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
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.