Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:00:03+00:00 2026-06-11T10:00:03+00:00

I’m creating a simple messaging application where users can login or register and communicate

  • 0

I’m creating a simple messaging application where users can login or register and communicate exclusively with me. Their user name and password is stored on a line in a .txt (that stores everyone elses) and our conversation is stored line by line in a unique user’sname.txt

When the user register or logs in I want to redirect them away from the form and to a standalone text area that displays our conversation below. However, when redirecting the user I’m not sure how to send their user name (usrNm) to the next php file so as to display the contents of our conversation (the file is their username). I’ve tried include(index.php) to no avail. How do also include index.php without passing the html. What’s the best way to do this?

I’m also confused about the general rules of using '' vs "", I believe "" allows variables to be inside and '' works for everything else? I was also told in html <input type="text".. the text should be in quotes, what are the benefits if it works without quotes? Another mini question is on line 30 if you wanna enlighten me. All advice is GREATLY appreciated!

//index.php
<?php
    echo "Login or register. ";
    //Ensures form exists and instantiates neccesary variables
    if (isset($_POST['usrNm'],$_POST['pass'],$_POST['passConf'])) {
        $usrNm = $_POST['usrNm'];
        $pass = $_POST['pass'];
        $passConf = $_POST['passConf'];
        $rec = file('userPass.txt');
        //Parses username from users txt file
        function usrName($indx){
            global $rec;
            $usrName = substr($rec[$indx], 0, stripos($rec[$indx], ' '));
            return $usrName;
        }
        //Parses password from users txt file
        function passWrd($indx){
            global $rec;
            $passWrd = trim(substr($rec[$indx], stripos($rec[$indx], ' ')));
            return $passWrd;
        }
        //Attempts to log user in
        if(!empty($usrNm)&&!empty($pass)&&empty($passConf)) {
            for($i=0;$i<count($rec);$i++) {
                //Logs user in
                if (($usrNm==usrName($i))&&($pass==passWrd($i))) {
                    //Outputs admin screen
                    if ($usrNm=='rich') {
                        for ($x=1; $x<count($rec); $x++) { 
                            //How to evaluate usrName($x) between link tags?
                            $usrNameLink = usrName($x);
                            echo "<a href='$com.php'>$usrNameLink</a> ";
                        }
                        break;
                    }
                    else header('Location: com.php');
                }
                //Wrong password
                elseif (($usrNm==usrName($i))&&($pass!=passWrd($i))) {
                    echo 'Wrong password.';
                    break;
                }
                //Username doesn't exist
                elseif (($i==count($rec)-1)&&($usrNm!=usrName($i))) {
                    echo 'Username doesn\'t exist.';
                }
            }
        }
        //Attempts to register user.
        elseif (!empty($usrNm)&&!empty($pass)&&!empty($passConf)) {
            for($i=0;$i<count($rec);$i++) {
                //Username taken
                if ($usrNm==usrName($i)) {
                    echo 'Username taken.';
                    break;
                }
                //Registers user: updates user txt file and creates txt file that saves correspondence between the user and me
                elseif (($i==count($rec)-1)&&($usrNm!=usrName($i))&&($pass==$passConf)) {
                    $handle = fopen('userPass.txt', 'a');
                    $handle2 = fopen("$usrNm.txt", 'a');
                    fwrite($handle, $usrNm.' '.$pass."\r\n");
                    fwrite($handle2, 'Richard: Here you can send me messages.');
                    fclose($handle);
                    fclose($handle2);
                    header('Location: com.php');
                }
                //Passwords don't match
                elseif (($i==count($rec)-1)&&($usrNm!=usrName($i))&&($pass!=$passConf)) {
                    echo 'Passwords don\'t match.';
                }
            }
        }
        //User didn't fill in the password field
        else{echo 'Fill in the required fields.';}
    }

?>
<form action="index.php" method="post">
    Username:<input name="usrNm" type="text"></input><br>
    Password:<input name="pass" type="password"></input><br>
    Confirm Password (only for registration):<input name="passConf" type="password"></input><br>
    <input name="submit" type="submit"></input>
</form>







//com.php
<?php
    include('index.php');
    if (isset($_POST['msg'])) {
        if (!empty($_POST['msg'])) {
            echo $usrNm;
        }
    }
?>
Welcome!
<form action="com.php" method="post">
    <textarea name="msg" cols="64" rows="4" type="text"></textarea><br>
    <input name="send" type="submit"></input>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:00:05+00:00Added an answer on June 11, 2026 at 10:00 am

    You are correct that double quotes parse variables, while single quotes do not. As to your second question in that paragraph, see here for rules regarding wrapping attribute values in quotes. There isn’t really all that much benefit in doing so aside from being able to have special characters within the value. I would also recommend reading this.

    As to your third question in that paragraph(the mini-question), I would recommend the following:

    echo "<a href='$com.php'>".usrName($x)."</a>";
    

    If you want to just use the function directly in the line.

    As to your very first question, I do not know of any such way to include a file without passing the html within. This might be such an answer, but it’s untested on my end, so I couldn’t tell you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I need to clean up various Word 'smart' characters in user input, including but
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.