Skip to content
Advertisement

PHP Include an Array

I am creating a flat file login system for a client (as their IT team does not want to give us a database)

I have worked off this:Easy login script without database which works perfect however…

I need to add a large list of logins and wanted to include them in a septrate file rather than in that script.

I have something like this:

<?php
session_start();

// this replaces the array area of the link above
includes('users.php');

//and some more stuff

?>

And in the users file I have

$userinfo = array(
                'kate'=>'inciterocks!',
                'nick'=>'inciterocks!'
                );

However it just literally outputs the text from that file. Is there a way I can include it so it just runs like it was in the main script?

Cheers 🙂

Advertisement

Answer

The statement name is actually include, and not includes.

Try the following:

include 'users.php';

And if your code is getting outputted as text, then it’s probably because you’ve missed the opening <?php tags. Make sure they’re present.

users.php should look something like this:

<?php

$userinfo = array(
                'kate'=>'inciterocks!',
                'nick'=>'inciterocks!'
                );

However, the closing tag is not a requirement and your code will work fine without it.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement