Current location: Hot Scripts Forums » Programming Languages » PHP » login script - a better way to die...


login script - a better way to die...

Reply
  #1 (permalink)  
Old 04-05-04, 05:50 AM
timsnell timsnell is offline
New Member
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
login script - a better way to die...

I'm a beginner at php so please excuse me if this is a simple question.

I recently impressed myself by managing to get a login script working from a tutorial I foun on the web. I tried to add html to it to make it look cooler. It all seems to be working well except for one aspect. When the user enters in wrong details for example the wrong password the scripts goes:

if ($_POST['passwd'] != $info['password']) {
die('Your Password Is Incorrect');
}

so the die command kills the script and prints Your Password Is Incorrect. However by killing the scipt it doesn't run the rest of the html on the page so it ends up looking strange. Is there away writing something along the lines of

if password is incorrect
go to location 'wrongpassword.php'

or a better way of not letting the user login and informing them that they've entered invalid info?

thanks!
Reply With Quote
  #2 (permalink)  
Old 04-05-04, 06:20 AM
zenonflare zenonflare is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
You could do the following:
PHP Code:

if ($_POST['passwd'] != $info['password']) {

echo 'Your Password Is Incorrect';
?>
//---------------
// Html here
//---------------
<?php
die();
}
?>
//---------------------------------------------------
// You'd need the same html here though aswell...
//---------------------------------------------------
Reply With Quote
  #3 (permalink)  
Old 04-05-04, 06:30 AM
MasQ's Avatar
MasQ MasQ is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Norway/Oslo
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Or you can just use the exit() command where you currently have the die command.
exit() will stop the php script, but not whatever comes after the php script.
eg.
PHP Code:

if ($_POST['passwd'] != $info['password']) { 

echo 
'Your Password Is Incorrect'; exit(); } 
?> 
Reply With Quote
  #4 (permalink)  
Old 04-06-04, 01:16 AM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
if ($_POST['passwd'] != $info['password']) {
die('Your Password Is Incorrect');
}

i whould just do something like

if ($_POST['passwd'] != $info['password']) {
include 'cannotlogin.php';
exit;
}
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net
Reply With Quote
  #5 (permalink)  
Old 04-06-04, 11:24 AM
Sargant Sargant is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Wales
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by MasQ
Or you can just use the exit() command where you currently have the die command.
exit() will stop the php script, but not whatever comes after the php script.
eg.
PHP Code:

if ($_POST['passwd'] != $info['password']) { 

echo 
'Your Password Is Incorrect'; exit(); } 
?> 
die; and exit; are actually both the same command - http://uk2.php.net/die
instead, try using return;
__________________
My Website: Sargant.Com
Noisebox, a simple but powerful shoutbox script
Reply With Quote
  #6 (permalink)  
Old 04-06-04, 11:43 AM
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
return is useless unless it's used in a function ..

you can define a function that will close the html stuff ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
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
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
looking for a login script sxmlink Script Requests 3 03-26-04 10:38 PM
login script required lochie Script Requests 2 03-06-04 07:44 PM
Need a login script that works with paypal. dgames Script Requests 3 12-04-03 07:58 AM
help me improve my login script please paulj000 PHP 8 08-15-03 05:37 PM


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