Graphic Design Forum and Web Design Forum  

Go Back   Graphic Design Forum and Web Design Forum »Web Design Forum »Programming Forum

Notices

Programming Forum Web and Software Programming Forum - Java, PHP, SQL etc.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 16-10-2007, 07:58 PM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,322
Default includes in an array?

How can you fill an array with info from an include? I've basically got:

Code:
$names = array( include("names.txt"));
...
The problem is that the include is passed through as html, and displays on screen the contents of the names.txt file as opposed to filling the array with details from the include.

Hope that made sense.

Harry
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #2 (permalink)  
Old 16-10-2007, 09:11 PM
LeadMagnet's Avatar
Mr. Tambourine Man
 
Join Date: Jun 2007
Location: Ireland
Gender: Male
Posts: 1,381
Default

Need more information.
How do you want the information to be inserted into the array?
Each line as an array element? By using a specific character as a delimiter?
What does your names.txt look like etc...
__________________
Subtlety is my middle name... and first and last in case you didn't get the point.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #3 (permalink)  
Old 17-10-2007, 06:57 PM
Andy's Avatar
Admin
 
Join Date: Jan 2007
Location: Berkshire, UK
Posts: 233
Default

doing it wrong hence its not working

PHP Code:
<?php
$url1 
= include('names.txt');
$url2 = include('namesmore.txt');

echo 
$url1 $url2;

?>
using the type of array your doing is more hard work than it needs to be and isn't recommended for passing function to anyhow. mostly used for countries and names than functions.

try the above.

*havn't coded in php for a while (asp .net geek) so hope it works. if not try
PHP Code:
<?php
$url1 
= include('names.txt');
$url2 = include('namesmore.txt');

echo 
$url1$url2;

?>
__________________
C# Developer, Passionate Nikon D80 Photographer, Motorcycle Lover
BlooGrape.co.uk
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #4 (permalink)  
Old 17-10-2007, 07:20 PM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,322
Default

@Andy, I know how to include files, but when I include it into an array it goes wrong. Here's what I'm working with:

the php:
Code:



Login








and names.txt:
Code:
"David" => "danjz.sL9bgaQ", "Admin" => "daguOy8u.JOqY",
It's basically a secure login (notice crypt) whereby all the users are called into the array from an external file (names.txt). The guy I'm developing this for wants to be able to add users at his will so I've made a html form which is kept in his admin area and when he enters a new users credentials, names.txt is appended. I'd use MySQL but a) I don't know it and b) apparently his host can't support it and c) it's just not worth me learning it for the amount im getting.

Cheers.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #5 (permalink)  
Old 17-10-2007, 08:49 PM
LeadMagnet's Avatar
Mr. Tambourine Man
 
Join Date: Jun 2007
Location: Ireland
Gender: Male
Posts: 1,381
Default

I have a headache so i'm not going to do much for you on this right now. But this should be enough to get you started in the right direction:


names.php =
PHP Code:
<?php
$passwords
["David"] = "danjz.sL9bgaQ";
$passwords["Admin"] = "daguOy8u.JOqY";
?>
login.php =
PHP Code:
<?php
include 'names.php';
print_r($passwords);
?>
You get the idea anyway.
Your admin form should modify the names.php file to add a new line like i've written above for each new user. Simple enough script.
Your names.php is then read in as an array already with the username as the key and the password as the corresponding value for each key.

You've got the wrong idea of an include.



Here's an example:

Take the 2 files above (names.php and login.php).
a (half) processed version of login.php looks like this right after the include is performed:

PHP Code:
<?php
$passwords
["David"] = "danjz.sL9bgaQ";
$passwords["Admin"] = "daguOy8u.JOqY";
print_r($passwords);
?>
If login.php included the names.txt file like you've created above, it would look like this

PHP Code:
<?php
"David" => "danjz.sL9bgaQ""Admin" => "daguOy8u.JOqY",
print_r($passwords);
?>
And what the hell is that as far as php is concerned? That's just a load of mumbo jumbo. ('"David" equal to or greater than "danjz.sL9bgaQ", "Admin" which is equal to or greater than "daguOy8u.JOqY",print_r($passwords);' er... ok... Computer says no! )

You get the picture.
__________________
Subtlety is my middle name... and first and last in case you didn't get the point.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #6 (permalink)  
Old 17-10-2007, 08:52 PM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,322
Default

Quote:
Originally Posted by LeadMagnet View Post
And what the hell is that as far as php is concerned? That's just a load of mumbo jumbo. ('"David" equal to or greater than "danjz.sL9bgaQ", "Admin" which is equal to or greater than "daguOy8u.JOqY",print_r($passwords);' er... ok... Computer says no! )

You get the picture.
I've followed a login tutorial and the code you're on about works a dream inside an array :s

Cheers for the rest though!
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #7 (permalink)  
Old 17-10-2007, 09:07 PM
LeadMagnet's Avatar
Mr. Tambourine Man
 
Join Date: Jun 2007
Location: Ireland
Gender: Male
Posts: 1,381
Default

It works a dream if you input it directly into an array, but as for an include... i'm not so sure... but like i said, me = headache, so i can't think straight right now.

The way i wrote above is how i'd do it anyway.
Easy to modify, easy to use.
__________________
Subtlety is my middle name... and first and last in case you didn't get the point.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #8 (permalink)  
Old 17-10-2007, 09:08 PM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,322
Default

Wicked, cheers! Thanks a lot. Get an asprin down you. Thanks again.

EDIT: Here you go mate:

Last edited by PR Design; 17-10-2007 at 09:20 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #9 (permalink)  
Old 18-10-2007, 10:42 AM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,322
Default

Ok, I'm really sorry to keep bothering you about this, but I have one last question. All the stuff you told me works a treat :) Thank you! But, when I set up the form which appends names.php it will add the new credentials after the closing php tag won't it? Is it possible to append a certain point in a file, ie before the ?>?

Thanks for all your help with this! Harry
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #10 (permalink)  
Old 18-10-2007, 11:04 AM
LeadMagnet's Avatar
Mr. Tambourine Man
 
Join Date: Jun 2007
Location: Ireland
Gender: Male
Posts: 1,381
Default

Yes, you use file to load that php file into an array.
The first and last entries in the array are your php opening and closing tags so you ignore those and rewrite them at the end.
PHP Code:
$passarray=fopen("names.txt","w+");
array_pop($passarray);
array_shift($passarray);
//your array no longer contains the php tags
// Add or remove your logins to/from the $passarray array right here.

foreach ($passarray as $line) {
fwrite($passarray$passarray);
}
fclose($passarray); 
er... i think i might have gotten that fwrite part wrong, doesn't look right. I dunno, i haven't tested it.
But try that out.
__________________
Subtlety is my middle name... and first and last in case you didn't get the point.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Includes Andy Programming Forum 3 25-01-2007 05:15 PM


All times are GMT. The time now is 07:38 AM.



Estetica Design Forum's Privacy Policy
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC5