Current location: Hot Scripts Forums » Programming Languages » PHP » login page


login page

Reply
  #1 (permalink)  
Old 04-09-04, 07:06 PM
Mister B.'s Avatar
Mister B. Mister B. is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
login page

okay, this all works untill I tried to add cookies... so here is my code

PHP Code:

<?php

session_start
();
if (
$_GET['sent'] == "yes") {
if (
$_POST['uname'] == ""){
include 
'top.php';
echo 
'You must fill out all fields.  You did not enter a username.<BR>';
echo 
'Please push the back button on your browser and fill out the field.';
} elseif (
$_POST['pword'] == "") {
include 
'top.php';
echo 
'You must fill out all fields.  You did not enter a password.<BR>';
echo 
'Please push the back button on your browser and fill out the field.';
}else{
$uname=$_POST['uname'];
$pword=$_POST['pword'];
$link mysql_connect("localhost","******","******");
mysql_select_db("evil",$link);
$result mysql_query ("SELECT * FROM users WHERE un='$uname' and up='$pword'");
$myrow mysql_fetch_array($result);
$admin $myrow['adm'];
$num=mysql_num_rows($result);
if(
$num=="0"){
include 
'top.php';
echo 
"Login Failed!";
}
else{
setcookie(login['user'], $_POST['uname']);
setcookie(login['admin'], $admin);
include 
'top.php';
echo 
$_COOKIE['login']['user'];
echo 
$_COOKIE['login']['admin'];
echo 
"Logged in Successfully as ";
echo 
$_POST['uname'];
echo 
".  Welcome back to www.ChaoticEvil.tk!";
}
}
}else{
include 
'top.php';
?>
<FORM name="login" METHOD="POST" ACTION="/login.php?sent=yes">
Username: <INPUT TYPE="text" NAME="uname">
Password: <INPUT TYPE="password" NAME="pword">
<INPUT TYPE="submit" NAME="SUBMIT" VALUE="LOGIN">
<?php
}
include 
'bot.php';
?>
Error: Parse error: parse error in c:\phpdev\www\login.php on line 29
why won't my cookies work??
__________________
God save us from the religious fanatics
Reply With Quote
  #2 (permalink)  
Old 04-09-04, 08:55 PM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
echo $_COOKIE['login']['user'];
echo $_COOKIE['login']['admin'];

Should be

echo "$_COOKIE['login']['user']"; // <~~ line 29 by the way
echo "$_COOKIE['login']['admin']";





AND


echo $_POST['uname'];

Should Be

echo "$_POST['uname']";


Try that.
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
  #3 (permalink)  
Old 04-09-04, 08:58 PM
Mister B.'s Avatar
Mister B. Mister B. is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
no dice, now it says
Parse error: parse error in c:\phpdev\www\login.php on line 26


HELP PLEASE!
__________________
God save us from the religious fanatics
Reply With Quote
  #4 (permalink)  
Old 04-10-04, 01:14 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by optix
echo $_COOKIE['login']['user'];
echo $_COOKIE['login']['admin'];

Should be

echo "$_COOKIE['login']['user']"; // <~~ line 29 by the way
echo "$_COOKIE['login']['admin']";





AND


echo $_POST['uname'];

Should Be

echo "$_POST['uname']";


Try that.
NEVER use double quotes with associative arrays !
check this post I wrote in another topic:
http://www.programmingtalk.com/showt...5523#post25523

what he did is correct ..

in your setcookie part, you shouldn't write this:
PHP Code:

setcookie(login['user'], $_POST['uname']); 

setcookie(login['admin'], $admin); 
you didn't provide all arguments needed for this function !!
you should give it time, path and domain !
also don't enclose its names user and admin with quotes ! the whole name should be quoted !
it should be like this:
PHP Code:

//this cookie will last for one week !

setcookie('login[user]'$_POST['uname'], time()+3600*24*7'/''DOMAIN_HERE'); 
setcookie('login[admin]'$admintime()+3600*24*7'/''DOMAIN_HERE'); 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 04-10-04, 01:16 PM
Mister B.'s Avatar
Mister B. Mister B. is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
okay, but what should I put for DOMAIN? localhost?
and if so just 'localhost' or 'http://localhost/'
__________________
God save us from the religious fanatics
Reply With Quote
  #6 (permalink)  
Old 04-10-04, 01:22 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
localhost isn't a real domain !
domain is something like this:
http://www.programmingtalk.com
in cookies it's preferable to use it like this:
.programmingtalk.com
so it can be accessable in subdomains as well ..
so in your situation:
PHP Code:

//this cookie will last for one week ! 

setcookie('login[user]'$_POST['uname'], time()+3600*24*7'/''.sagaofchaos.tk'); 
setcookie('login[admin]'$admintime()+3600*24*7'/''.sagaofchaos.tk'); 
but if you want the cookie to be strictly used in main domain only then add www but without http://
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #7 (permalink)  
Old 04-10-04, 01:26 PM
Mister B.'s Avatar
Mister B. Mister B. is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
right got you... -- saga of chaos wow that was a long time ago... Should update that.

Okay, one more question. right now I am just testing on apache on my computer so the site is like http://localhost/login.php or whatever... what should I use in my cookie then?
__________________
God save us from the religious fanatics
Reply With Quote
  #8 (permalink)  
Old 04-10-04, 01:37 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
if you are running the script in your local machine then just leave it blank in the domain ! meaning :
PHP Code:

//ONLY if you are running on localhost

setcookie('login[user]'$_POST['uname'], time()+3600*24*7'/''');
setcookie('login[admin]'$admintime()+3600*24*7'/'''); 
but when you upload it to real world then make sure that you change it to the domain name you are using !
and note, you shouln't add file names into the domain or the script wont work properly !
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #9 (permalink)  
Old 04-10-04, 01:45 PM
Mister B.'s Avatar
Mister B. Mister B. is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
thanks alot, I will test it in a bit
__________________
God save us from the religious fanatics
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically refresh page after page load failure jdugger JavaScript 3 08-05-10 09:16 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
site search page divadov ASP 1 04-14-04 06:39 AM
Header Warnings are gone, but page still does not work correctly stscac PHP 0 02-16-04 11:02 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 10:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.