Jump to content

Usernames into an array


MuseiKaze

Recommended Posts

Hi there. Im pretty new to php and this forum, but I was just wondering if I could get some help with part of a chat room that im writing.

 

Basically I have a form where users enter their usernames then I want to put each username into an array and use with a session onto another page where all the users can be echoed as a list. Is this possible?

 

Thanks =)

Link to comment
Share on other sites

I dont have anything currently for the user list section currently, I did some experimenting with adding the usernames to a text file each time someone logs in and then deleting that username when they log out, but that didnt really turn out well =P 

 

Im still all new to php, so sorry if i dont explain myself heaps well.

 

But I was thinking something like this could be used but im not sure how to store and split each $username = $_POST['username']; into an array.

 

index.php

 

<form action="chat.php" method="post">

<input name="username" type="text" size="25" maxlength="20">

<input value="Login" type="submit"></form>

 

chat.php

 

<?php

session_start();

 

$username = $_POST['username'];

 

$users = array('username[0]','username[1]','username[2]');

 

$_SESSION['users'] = $users;

?>

 

users.php

 

print $users;

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.