|
Form Validation w/ Cookies, Errors?
Form Validation w/ Cookies, Errors?
Currently viewing this thread: 1 (0 members and 1 guests)
 September 4th, 2004 11:23 PM
Insomniac
Status: Offline!
Form Validation w/ Cookies, Errors?
Here is my code:
<?php
ob_start();
if ($submit_login) {
include ("config.php");
$Connect = mysql_connect ($MySQL_Host, $MySQL_User, $MySQL_Pass);
mysql_select_db ($MySQL_DB);
$Get_Action_UN = "SELECT * from UserList where Username='$Login[Username]' AND Password='$Login[Password]'";
$Get_Query_UN = mysql_query($Get_Action_UN);
$Get_Amount_UN = mysql_num_rows($Get_Query_UN);
if ($Get_Amount_UN == '1') {
setcookie ("C_User", $Login[Username], time()+3600);
setcookie ("C_Pass", $Login[Password], time()+3600);
setcookie ("C_UserType", $UserType, time()+3600);
setcookie ("C_LoggedIn", "True", time()+3600);
echo ("<font>$Txt13d2<br /></font>");
$Set_Cookies = "TRUE";
if ($Set_Cookies == "TRUE") {
echo ("<font>$Txt14d2 $_COOKIE[C_User] $_COOKIE[C_Pass] $_COOKIE[C_UserType] $_COOKIE[C_LoggedIn]</font>");
}
} elseif ($Get_Amount_UN == '0') {
echo ("<font><b>$Txt10d2 $Login[Username] $Txt11d2</b></font>");
}
mysql_close ($Connect);
}
ob_end_flush();
?>
Edited Script From Original Post
What this is to do, is get information from the login form, process the Username and Password to see if they are correct from the database ( Guest // Guest ), then if they are, then it will create the cookies for one hour.
I understand I could use sessions, but I dont want to. Because this is the "Lite" version. And I want to put sessions in the "Pro" version .
So, you can go to http://blizter.net/ba_lite/?id=login and put in Guest // Guest , and then see the error I am getting with the code.
Any help is greatly appreciated. 
___________________
Spoono :: WebDapper :: ValidCode
Last edited by Spookster187, September 4th, 2004 11:43 PM (Edited 1 times)
 September 4th, 2004 11:31 PM
Neversidian
Status: Offline!
Sessions are just as 'lite' as a cookie. Sessions just end when the browser is closed as opposed to cookies ending when the time specified expires.
I don't see why you are getting the 'Headers already sent' errors, so, try putting ob_start(); at the top and ob_end_flush(); at the bottom
___________________
"Hey, **** YOU!"
 September 4th, 2004 11:36 PM
Insomniac
Status: Offline!
Originally posted by Stevie
Sessions are just as 'lite' as a cookie. Sessions just end when the browser is closed as opposed to cookies ending when the time specified expires.
I don't see why you are getting the 'Headers already sent' errors, so, try putting ob_start(); at the top and ob_end_flush(); at the bottom
I know what sessions are. I also know they are more secure and are put on the server. That is why I intend to use them on the Pro version of BillAxis .
Cookies are for Lite, meh. I put the ob_start(); and ob_end_flush(); inside the if command where the cookies are. And its the same error.
Personally Stevie, I think this is like one of those worlds most stupid and simpliest errors, and we are just seeing right past it o.O :-P.
___________________
Spoono :: WebDapper :: ValidCode
 September 4th, 2004 11:41 PM
Neversidian
Status: Offline!
You aren't setting a time on the cookies, so therefore they aren't being set for an hour.
<?php
setcookie ("C_User",$Login[Username]);
?>
should be
<?php
setcookie ("C_User",$Login['Username'],time()+3600);
?>
Try this
<?php
if ($submit_login) {
include ("config.php");
$Connect = mysql_connect ($MySQL_Host, $MySQL_User, $MySQL_Pass);
mysql_select_db ($MySQL_DB);
$Get_Action_UN = "SELECT * from UserList where Username='".$Login['Username']."' AND Password='".$Login['Password']."';";
$Get_Query_UN = mysql_query($Get_Action_UN);
$Get_Amount_UN = mysql_num_rows($Get_Query_UN);
if ($Get_Amount_UN == '1') {
setcookie ("C_User",$Login['Username'],time()+3600);
setcookie ("C_Pass",$Login['Password'],time()+3600);
setcookie ("C_UserType",$UserType,time()+3600)
setcookie ("C_LoggedIn","True",time()+3600);
echo ("<font>".$Txt13d2."</font>");
$Set_Cookies = "TRUE";
if ($Set_Cookies == "TRUE") {
echo ("The cookies are: C_User, C_Pass,C_UserType, and C_LoggedIn");
}
} elseif ($Get_Amount_UN == '0') {
echo ("<font><b>".$Txt10d2 . $Login['Username'] . $Txt11d2."</b></font>");
}
mysql_close ($Connect);
}
?>
___________________
"Hey, **** YOU!"
 September 4th, 2004 11:47 PM
Insomniac
Status: Offline!
Ok, I edited the code above. Although there are some flaws in your code aswell.
<?php
echo ("The cookies are: C_User, C_Pass,C_UserType, and C_LoggedIn");
?>
Thanks to the echo command, it will say exactly that, not the cookies.
<?php
echo ("<font><b>".$Txt10d2 . $Login['Username'] . $Txt11d2."</b></font>");
?>
The periods aren't necessary. Plus, this works already, the way I had it. Its the IF User and Pass dont exist together in the same row. The way I have it works fine.
The Anything with Txt##d# is my language file I am making. So like $Txt14d2 would be Text Line 14, dash, block 2, just to let ya know :P
___________________
Spoono :: WebDapper :: ValidCode
 September 4th, 2004 11:53 PM
Neversidian
Status: Offline!
Originally posted by Spookster187
Ok, I edited the code above. Although there are some flaws in your code aswell.
lol, dude there are so many flaws in yours, im not going to begin to start.
The periods are concatenation. It is not wise to
the correct way would be
<?php
echo "Hello, ".$var."!";
?>
___________________
"Hey, **** YOU!"
 September 5th, 2004 12:00 AM
Insomniac
Status: Offline!
Amazingly, your stride for the error code (couldnt find them) worked... but. As I expected, when I logged in with correct information, it printed C_User and so on as text, instead of not showing.
___________________
Spoono :: WebDapper :: ValidCode
 September 5th, 2004 12:04 AM
Insomniac
Status: Offline!
Excuse my double post, just didnt want this to be added to another unseen.
I am going to use:
<?php
echo "<font>".$Txt14d2 . $_COOKIE[C_User] . $_COOKIE[C_Pass] . $_COOKIE[C_UserType] . $_COOKIE[C_LoggedIn]."</font>";
?>
instead of
<?php
echo ("The cookies are: C_User, C_Pass,C_UserType, and C_LoggedIn");
?>
because mine actually reads them as cookies, and since it cannot find them, it is not showing them .
___________________
Spoono :: WebDapper :: ValidCode
 September 5th, 2004 12:13 AM
Neversidian
Status: Offline!
Well, you are going to echo the cookie data, what the cookie holds in it. I'm not sure thats what you wanted, I think you wanted to echo the cookie names. And plus,
<?php
echo $_COOKIE[C_User]
?>
is going to return an error because PHP is going to think that C_User is a constant. You need to
<?php
echo $_COOKIE['C_User'];
?>
___________________
"Hey, **** YOU!"
 September 5th, 2004 12:17 AM
Insomniac
Status: Offline!
Ok, thanks for that part. And no, I wanted to display the contents just to see if it worked how I wanted, as 2 cookies are from the form, 1 is from the database, and 1 is a value itself for the cookie.
Now, we got all these awesome tricks with the .'s and whatnots, but we still haven't figured out why its giving us the header error 
___________________
Spoono :: WebDapper :: ValidCode
|