ted_chou12's Avatar, Join Date: Nov 2006
Go4Expert Member
by the way, where do I place my html code?
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Place the HTML preferably after the session PHP code.
ted_chou12's Avatar, Join Date: Nov 2006
Go4Expert Member
<?php
ob_start();
session_start(); ?>
**********
You mean here?
**********
<? require_once ("functions.php");

if (checkLoggedin())
echo "<H1>You are already logged in - <A href = \"login.php?do=logout\">logout</A></h1>";
else
echo "<H1>You are not logged in - <A href = \"login.php\">login</A></h1></h1>";
?>
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Yeah, right! But you may need to include or require your files before that, you can include your files, before the session code.
ted_chou12's Avatar, Join Date: Nov 2006
Go4Expert Member
okay, ive solved that problem, now, if i want to store username and password in another txt file, what would i have to put in the main php page codes?
eg.
Code:
if(file('logindata.txt'))
return true;
else
return false;
so far, i tried file(), fileread(), file_ get_ contents(), include(), require()...etc.. and a bunch of them, but none works, can you give me a suggestion?
pradeep's Avatar, Join Date: Apr 2005
Team Leader
It would be something like this

Code: PHP
<?
$username = $_SESSION['usr'];
$pwd = $_SESSION['pwd'];

$h = fopen("userdata.txt");
fwrite($h,"$username\n$pwd\n\n");
fclose($h);
?>
ted_chou12's Avatar, Join Date: Nov 2006
Go4Expert Member
where do i paste this in?
<?$username = $_SESSION['usr'];$pwd = $_SESSION['pwd'];$h = fopen("userdata.txt");fwrite($h,"$username\n$pwd\n \n");fclose($h);?>
and what do the "\n" stand for?
ted_chou12's Avatar, Join Date: Nov 2006
Go4Expert Member
oh no, sorry, i think i didn't say it clearly, what i wish is to extract the information of username and password FROM the text file, not store them into the txt files. Thanks for understanding.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
\n stands for newline. Visit http://in2.php.net/types.string for more escape sequences.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Well then you have to store the data in text files, in a specific format say user:location:age OR user#ocation#age, so that the data retrieval becomes easy.
All you have to do is to read the text file line by line, and split it by the separator you have chosen (: or #) and then check the username part for a match. Bingo! you got your record.