PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 1st, 2009, 01:06 PM
Peuplarchie's Avatar
Peuplarchie Peuplarchie is offline
Stand
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Québec
Posts: 205 Peuplarchie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 1 m 37 sec
Reputation Power: 3
Post php4 - Match $var in text file ?

Good day to you all,
stupid as it sound, all the thing that I have tried to match a variable into a text file and execute according to it result.


PHP Code:
 $active "user_list.txt";
$pos strpos($active$_SESSION['username']);
if (
$pos === false) {
echo 
"<b id=\"userinfo\"><img src=\"enligne.png\" valign=\"bottom\" width=\"13px\"/></b>";
} else {
echo 
"<b id=\"userinfo\"><img src=\"horsligne.png\" valign=\"bottom\" width=\"13px\"/></b>";



Thanks !
__________________
That's why we are not alone on earth, to help each other !
Let's build !

Reply With Quote
  #2  
Old July 1st, 2009, 02:24 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 400 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 15 h 59 m 8 sec
Reputation Power: 2
What are you trying to match the string in the text file to? a username?
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge.

Reply With Quote
  #3  
Old July 1st, 2009, 03:57 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 400 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 15 h 59 m 8 sec
Reputation Power: 2
PHP Code:
<?php

//Start the session for this page....
session_start();


//Create a username, probably already done somewhere else in the application...
$_SESSION['username'] = 'captain_man';

//Point to file
$filename "usernames.txt";

//Opens the file and assigns reference point
$file fopen($filename"r");

//Reads the reference point
$string fread($file,filesize($filename));

//Creates an array, one element for each new line
$each_line explode("\n",$string);

//Not sure if this part is just for windows or not (I used notepad to create the usernames.txt file), but it removes the \r character(s) from the array
$each_line str_replace("\r","",$each_line);

//Sets a variable to 0 to tell whether a user was found or not...
$yeah 0;

//Splits the array into each element
foreach($each_line as $key => $value) {

//Checks to see if the array element is the same as the session variable 'username'
if($_SESSION['username'] == $value) {

//If it finds a match, echos "You are a User", sets yeah to 1 and stops the foreach loop
echo "You are a user!";

$yeah 1;

break;

}

}

//If no usernames are matched to the session variable, echo 'not a user'
if($yeah!=1) {

echo 
"You are not a user...";

}

?>


Using the text file in the same directory as the php file:

Code:
jamestrowbridge
billy_bob
captain_man

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php4 - Match $var in text file ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
Stay green...Green IT