VisBasDude
Programmer
Hi there, im relativly new to PHP but really like it and at the moment im just experimenting, currently im trying to make a login page. This is going well but now i want to have global varibles which will contain user details over the pages. I presume using sessions is the correct way to do this. The code below doesnt seem to work for me, it doesnt seem to write to the sessions, could someone please help me out.
<?
session_start();
session_register("GlobalUsername"
function CheckUsernameandPassword($Username,$Password){
$Filename = "Users.txt";
$Open = fopen($Filename, "r"
$Found = FALSE;
if($Open) {
$Data = file($Filename);
for ($n = 0; $n < count($Data);
$n++){
$GetData = explode("\t",$Data[$n]); // Gets data and splits it up
$FoundUsername = "$GetData[0]";
$FoundPassword = "$GetData[1]";
$FoundEmailAddress = "$GetData[4]";
$FoundAdmin = "$GetData[7]";
$FoundAdvancedUser = "$GetData[8]";
$FoundDeleted = "$GetData[9]";
if(("$Username" == "$FoundUsername"&&("$Password" == "$FoundPassword"&&("$FoundDeleted" == "No"){
$Found = TRUE;
$GlobalUsername = "$FoundUsername"; }// I want this varible to be global
}
}
}
if ("$Found" == TRUE){
$CallFunction=LoginOK(); // If user found call this page
} else {
$CallFunction=LoginError();}
}
?>
<html>
<head>
<title>Logged In</title>
</head>
<body>
<?php
$CallFunction=CheckUsernameandPassword("$Username","$Password"
function LoginOK (){
print("<p align=\"left\"><font face=\"Arial Rounded MT Bold\" size=\"6\">Welcome $GlobalUsername </font></p>" // Here i wanted to put the username into the text
print($GlobalUsername);
print("<p align=\"left\"><font face=\"Arial Rounded MT Bold\">Login Ok <A HREF=\" Here</A></P>"
}
function LoginError (){
print("Login Error"
}
?>
</body>
</html>
I would be very greatful if you could. Thankyou James
<?
session_start();
session_register("GlobalUsername"
function CheckUsernameandPassword($Username,$Password){
$Filename = "Users.txt";
$Open = fopen($Filename, "r"
$Found = FALSE;
if($Open) {
$Data = file($Filename);
for ($n = 0; $n < count($Data);
$n++){
$GetData = explode("\t",$Data[$n]); // Gets data and splits it up
$FoundUsername = "$GetData[0]";
$FoundPassword = "$GetData[1]";
$FoundEmailAddress = "$GetData[4]";
$FoundAdmin = "$GetData[7]";
$FoundAdvancedUser = "$GetData[8]";
$FoundDeleted = "$GetData[9]";
if(("$Username" == "$FoundUsername"&&("$Password" == "$FoundPassword"&&("$FoundDeleted" == "No"){
$Found = TRUE;
$GlobalUsername = "$FoundUsername"; }// I want this varible to be global
}
}
}
if ("$Found" == TRUE){
$CallFunction=LoginOK(); // If user found call this page
} else {
$CallFunction=LoginError();}
}
?>
<html>
<head>
<title>Logged In</title>
</head>
<body>
<?php
$CallFunction=CheckUsernameandPassword("$Username","$Password"
function LoginOK (){
print("<p align=\"left\"><font face=\"Arial Rounded MT Bold\" size=\"6\">Welcome $GlobalUsername </font></p>" // Here i wanted to put the username into the text
print($GlobalUsername);
print("<p align=\"left\"><font face=\"Arial Rounded MT Bold\">Login Ok <A HREF=\" Here</A></P>"
}
function LoginError (){
print("Login Error"
}
?>
</body>
</html>
I would be very greatful if you could. Thankyou James