Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

95 users online



Form Validation w/ Cookies, Errors?

Form Validation w/ Cookies, Errors?

Currently viewing this thread: 1 (0 members and 1 guests)


Spookster187

Spookster187

Insomniac
Status: Offline!

Form Validation w/ Cookies, Errors?

Here is my code:

PHP:


<?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"$UserTypetime()+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 Smile.

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. Smile

___________________

Spoono :: WebDapper :: ValidCode

Last edited by Spookster187, September 4th, 2004 11:43 PM (Edited 1 times)

Stevie

Stevie

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!"

Spookster187

Spookster187

Insomniac
Status: Offline!
Quote:

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 Wink.

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

Stevie

Stevie

Neversidian
Status: Offline!

You aren't setting a time on the cookies, so therefore they aren't being set for an hour.

PHP:

<?php
   setcookie 
("C_User",$Login[Username]);

?>

should be

PHP:

<?php
   setcookie 
("C_User",$Login['Username'],time()+3600);

?>


Try this

PHP:

<?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!"

Spookster187

Spookster187

Insomniac
Status: Offline!

Ok, I edited the code above. Although there are some flaws in your code aswell.

PHP:

<?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:

<?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 Wink :P

___________________

Spoono :: WebDapper :: ValidCode

Stevie

Stevie

Neversidian
Status: Offline!
Quote:

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

PHP:

<?php
echo "$var";
?>

the correct way would be

PHP:

<?php
echo "Hello, ".$var."!"
?>

___________________

"Hey, **** YOU!"

Spookster187

Spookster187

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

Spookster187

Spookster187

Insomniac
Status: Offline!

Excuse my double post, just didnt want this to be added to another unseen.

I am going to use:

PHP:

<?php
echo "<font>".$Txt14d2 $_COOKIE[C_User] . $_COOKIE[C_Pass] . $_COOKIE[C_UserType] . $_COOKIE[C_LoggedIn]."</font>";
?>

instead of

PHP:

<?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 Smile.

___________________

Spoono :: WebDapper :: ValidCode

Stevie

Stevie

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:

<?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:

<?php
echo $_COOKIE['C_User'];
?>

___________________

"Hey, **** YOU!"

Spookster187

Spookster187

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 Tongue

___________________

Spoono :: WebDapper :: ValidCode

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0127 seconds.