Dr Ben Warne Posted December 6, 2006 Share Posted December 6, 2006 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 joinBUT i want it to search to see whether the file exists (to see if someone is already waiting) the go to a new screenI 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 More sharing options...
Dr Ben Warne Posted December 6, 2006 Author Share Posted December 6, 2006 Can anyone help? Im still having no luck >:( Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-136447 Share on other sites More sharing options...
kenrbnsn Posted December 6, 2006 Share Posted December 6, 2006 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 Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-136455 Share on other sites More sharing options...
Dr Ben Warne Posted December 7, 2006 Author Share Posted December 7, 2006 [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 https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-136798 Share on other sites More sharing options...
Dr Ben Warne Posted December 7, 2006 Author Share Posted December 7, 2006 Is there a code that creates a file and adds to it? Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-136873 Share on other sites More sharing options...
Dr Ben Warne Posted December 8, 2006 Author Share Posted December 8, 2006 Ia ir function create? Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-137399 Share on other sites More sharing options...
Orio Posted December 8, 2006 Share Posted December 8, 2006 [url=http://php.net/fopen]fopen()[/url] basicly opens files. But if the file doesnt exist, it creates it (and then opens it). So you just need to use [url=http://php.net/fopen]fopen()[/url] :)Orio. Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-137400 Share on other sites More sharing options...
Qtix Posted December 8, 2006 Share Posted December 8, 2006 for what do you want to use it?cause its best to avoid fopen and fwrite Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-137402 Share on other sites More sharing options...
Dr Ben Warne Posted December 8, 2006 Author Share Posted December 8, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-137457 Share on other sites More sharing options...
Dr Ben Warne Posted December 10, 2006 Author Share Posted December 10, 2006 any ideas? Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-138247 Share on other sites More sharing options...
Dr Ben Warne Posted December 11, 2006 Author Share Posted December 11, 2006 [quote author=Dr Ben Warne link=topic=117595.msg481888#msg481888 date=1165709433]any ideas?[/quote]Any?? Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-138730 Share on other sites More sharing options...
trq Posted December 11, 2006 Share Posted December 11, 2006 [url=http://php.net/fopen]fopen[/url]. Link to comment https://forums.phpfreaks.com/topic/29682-creating-a-file-to-add-to/#findComment-138736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.