Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2004, 09:05 AM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Spookster187 Send a message via AIM to Spookster187 Send a message via MSN to Spookster187 Send a message via Yahoo to Spookster187
Default Form Validation w/ Cookies, Errors?

Hey all, nice community you got going. Just to introduce myself to be kind, I am Ryan Barr (Spooky) of Spoono.com and The owner of Blizter.net, and the owner, founder, and coder of BillAxis.

The issue I am having is based on BillAxis. It is (or will be) a Webhosting Client System (Billing, Invoices, Etc). I started to make it so I could have a whack at blowing PHPCoin out of the water from hate. So here it is: http://blizter.net/ba_lite/ . Yes, I understand, plain... the thing is, I need to get the login (if you click it, it appears), to work. After the login works, I will make the admin panel to control all of the content on the other pages.

Here is my code:
Code:
<?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]);
   setcookie ("C_Pass", "$Login[Password]");
   setcookie ("C_UserType", "$UserType");
   setcookie ("C_LoggedIn", "True");

   echo ("$Txt13d2");

   $Set_Cookies = "TRUE";

   if ($Set_Cookies == "TRUE") {
     echo ("The cookies are: $_COOKIE[C_User] $_COOKIE[C_Pass] $_COOKIE[UserType] $_COOKIE[LoggedIn]");
   }

 } elseif ($Get_Amount_UN == '0') {
   echo ("<b>$Txt10d2 $Login[Username] $Txt11d2</b>");
 }
 
 mysql_close ($Connect);
}

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

Ryan Barr
&lt;('.'&lt;) (&gt;'.'&lt;) (&gt;'.')&gt;
 
Old September 10th, 2004, 05:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

hey Spookster :D

first of all, you need to add some stuff for your code. if you want to specify the expiration time for a cookie you need to invoke the setcookie() function with more params...

bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]])

that's how php.net has it... look at your code and go to the lines where you have setcookie() called 4 times, this is how i would do it:


global $HTTP_COOKIE_VARS;
$expire = time() + 3600; //expires within next hour

setcookie ("C_User", $Login[Username],$expire,"/","",0);
$HTTP_COOKIE_VARS["C_User"] = $Login[Username];

setcookie ("C_Pass", "$Login[Password]",$expire,"/","",0);
$HTTP_COOKIE_VARS["C_Pass"] = $Login[Password];

setcookie ("C_UserType", "$UserType",$expire,"/","",0);
$HTTP_COOKIE["C_UserType"] = $UserType;

setcookie ("C_LoggedIn", "True",$expire,"/","",0);
$HTTP_COOKIE["C_LoggedIn"] = "True";


make sure that you don't use $_COOKIE, it seems that there's no difference between $HTTP_COOKIE_VARS, but for some reason $_COOKIE is messy, and if you use $HTTP_COOKIE_VARS array make sure you call the header('location: whatever.php');

you have to declare that $HTTP_COOKIE_VARS is global like in the example above and you MUST call header() after all cookies are set....

hope that helped you




www.campusgrind.com the college portal
 
Old September 10th, 2004, 09:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Moharo,

HTTP_*_VARS IS A BAD THING. To see what I'm talking about, look at Nik's reply to this thread.

$_COOKIE is preferred to the depreciated HTTP vars.

BTW, how is $_COOKIE messy?

Snib

<><
 
Old September 10th, 2004, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

Hey Snib

I'm writing about $_COOKIE as messy because some time ago I had some real problems with cookies when I used $_COOKIE, it (as usually) concerned IE 6. I read somewhere that IE6 uses something called P3P (Platform for Privacy Preferences) and it filters out third party cookies. It surely didn't work, cookies expired in no time. I know that $HTTP_COOKIE_VARS is old but it saved my day.... older doesn't mean it's bad :D



www.campusgrind.com the college portal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
asp, store, retrieve form value from cookies? kumiko Classic ASP Basics 0 November 24th, 2007 12:33 PM
Form not refreshing after form validation Mimi Javascript How-To 0 August 25th, 2003 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.