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
https://forums.phpfreaks.com/topic/180810-usernames-into-an-array/
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;

Archived

This topic is now archived and is closed to further replies.

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