Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 9th, 2003, 10:40 PM
Vantera Vantera is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: South Coast of NSW, Australia
Posts: 108 Vantera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to Vantera
Article Discussion: PHP for Beginners by a Beginner: Simple Login, Logout, and Sessio

If you have any questions or comments about this article please post them here.

This forum post relates to this article
__________________
Kind Regards,
John Rebbeck
john@interspire.com
ICQ# 74637937

Reply With Quote
  #2  
Old February 10th, 2003, 10:19 AM
arnorg arnorg is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 13 arnorg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is a very bad article, it looks like you havenīt checked that session manipulation has changed in php 4.2 version and you are stuck in php3...

You arenīt checking for the session var $_SESS[user]; but $user, and thatīs why anyone can view a member area of the page, by posting a var or slice it in the ?url query.


When a user submits information, you check just for $user but not $_GET[user] so we donīt know is itīs a form var or just a var thatīs has been sliced with the url?user=admin


Very unsecure code that you use in this article..iīm sorry i you take review badly.

Reply With Quote
  #3  
Old February 11th, 2003, 04:36 AM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via AIM to Jeb.
If you weren't a PHP beginner, I probably would've been saying 'Why the hell aren't you using $_SESSION???'

But, all arrogance aside, the best way to learn is to teach...The structure of the article is good. It teaches you what you need to know and does so effectively. It's got everything necessary for a beginner to learn simple authentication and session handling.

However, as arnorg so eloquently mentioned (), it does need to be updated to support PHP 4.3.0. Instead of session_register, session_is_registered and session_unregister, use $_SESSION, isset($_SESSION['varName']) and unset($_SESSION['varName']).

register_globals is a dangerous thing - best outsmart it with the autoglobals

If you change these couple of things, the article will be improved exponentially

-Jeb.
__________________
Jeb.

AIM: JebediahMc - PM Me - E-Mail Me


Reply With Quote
  #4  
Old February 13th, 2003, 01:36 AM
mbennett mbennett is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 mbennett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how could I use this article to redirect a user to a different page like if user_id is 3 then you will go to /page.php?id=3


TIA

Reply With Quote
  #5  
Old February 15th, 2003, 08:31 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Quote:
Originally posted by mbennett
how could I use this article to redirect a user to a different page like if user_id is 3 then you will go to /page.php?id=3


TIA


Tia:
You could do this.. however it might be in your better interest to do something like this:

In the database of users have something such as an authlevel field, and have normal users set to 1, moderators set to 2, admins set to 3, or so on.. that way when they load the page, you can have something like this function to get that access level:

PHP Code:
function getAccLvl(){       
    
session_start();
    
$userpass md5($_SESSION['userpw']);
    
$username $_SESSION['usernm'];
    @
$svrConn mysql_connect("localhost""dbUser""dbUserPass") or die ("Couldn't connect to the db server.\n");
    if(
$svrConn)
    {
        
$dbConn mysql_select_db("databasename"$svrConn) or die("Could not connect to the database<br>");
        
        if(
$dbConn)
        {
            
$strQuery "select * from users ";
            
$strQuery .= "where username = '$username'";
            
$strQuery .= " and password = '$userpass'";

            
$results mysql_query($strQuery);
            
$result mysql_fetch_row($results);
            if (
$result){
                return 
$result[3];
            }
            else{
                return 
"0";
            }
        }
    }



I know it's not the best function, but for all intensive reasons it works for what you would need. The structure of the database may vary for you though.. Mine is set like this:

Field 1 - Auto incriment userId Field2 - The username Field 3 - The users MD5'd password Field4 - the auth level
So that should explain the return $result[3]; <It would be equal to field 4 in the database>.. and if they aren't logged in it returns 0 for guest.

You can get the access level and assign it to a variable like so:
PHP Code:
 $accLvl getAccessLevel(); 


Then from there, since you have an access level of the person, whomever they are <The authlevel field is set to default of 1> you can do a case statement if you want or a redirect, whichever..

for example
PHP Code:
switch($accLvl){
    case 
3:{
        
//header('location: whatevertheadminpageis.php');
        
break;
    }
    case 
2:{
        
//header('location: whateverthemoderatorpageis.php');
        
break;
    }
    case 
1:{
        
//header('location: whateverthegeneralpageis.php');
        
break;
    }
    case 
0:{
        
//header('location: /');
    
}



not that you have to do it that way, but it could make it easier on yourself and that way you dont have the inherant risk of people trying to forge themselves as an administrator, for example..

Reply With Quote
  #6  
Old February 15th, 2003, 08:31 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Sorry for the bigass post too :P

lol.. Hope that helped..

And btw, this was a decent beginners article for sessions

Reply With Quote
  #7  
Old February 17th, 2003, 04:19 PM
Tiny Tiny is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Very north of Sweden
Posts: 2 Tiny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm so glad someone could finally create something for us (forever) beginners!
I have encountered the same arrogance when it comes to *some* of those who allready know the scripting language. But most people are very generous and helpful.

So please! keep up the good work and be sure that a bunch of us who know and understand less than little are very pleased.

Also, I don't feel like learning all that much of the php scripting. So I'm also glad there is a wysiwyg editor for php. And why don't I want to learn, some may ask? Because I have my head full of game making scripts so there simply isn't any more room. Plus I'm an old lady, which isn't an excuse I guess. But still...

Reply With Quote
  #8  
Old February 21st, 2003, 04:12 PM
skatablaze skatablaze is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: cincinnati
Posts: 8 skatablaze User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to skatablaze
Unhappy Log IN forms

When i goto log in with a username i created in the db i get this when i hit log in. I think its because the tutorial showed older script and its not working with the new.Any help on this would be greatly appriciated

Warning: session_start() [function.session-start]: open(/tmp\sess_247cebe1c0bc5e837b12f4919cec1dc2, O_RDWR) failed: No such file or directory (2) in C:\Documents and Settings\UserX001\My Documents\My Webs\login.php on line 48

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Documents and Settings\UserX001\My Documents\My Webs\login.php:7) in C:\Documents and Settings\UserX001\My Documents\My Webs\login.php on line 48

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Documents and Settings\UserX001\My Documents\My Webs\login.php:7) in C:\Documents and Settings\UserX001\My Documents\My Webs\login.php on line 48

Notice: Array to string conversion in C:\Documents and Settings\UserX001\My Documents\My Webs\login.php on line 49

Fatal error: Call to undefined function: array() in C:\Documents and Settings\UserX001\My Documents\My Webs\login.php on line 49

Warning: Unknown(): open(/tmp\sess_247cebe1c0bc5e837b12f4919cec1dc2, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

Reply With Quote
  #9  
Old February 21st, 2003, 04:29 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
it looks like it's trying to write to the /tmp directory <which is what it would be for a unix machine>

Look in your php.ini file for
Code:
 session.save_path = /tmp


and change it to something like
Code:
 session.save_path = c:\temp 


and see if that works..

as for the other errors, put ob_start(); at the beginning of your php file and ob_flush(); at the very end

Hope that helps.

Reply With Quote
  #10  
Old February 22nd, 2003, 12:20 AM
skatablaze skatablaze is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: cincinnati
Posts: 8 skatablaze User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to skatablaze
Question sorry to bother you again

i got the error.

Parse error: parse error, unexpected T_STRING in C:\Documents and Settings\UserX001\My Documents\My Webs\login.php on line 38

Heres the whole on the page thats giving me a problem:

<?PHP
ob_start();
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
if (!isset($username) || !isset($password)) {
header( "Location: http://skata.kicks-ass.net/index.php");
}
//check that the form fields are not empty, and redirect back to the login page if they are
elseif (empty($username) || empty($password)) {
header( "Location: http://skata.kicks-ass.net/index.php");
}
else{

//convert the field values to simple variables

//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);


//set the database connection variables

$dbHost = "localhost";
$dbUser = "ODBC";
$dbDatabase = "members";

//connet to the database

$db = mysql_connect("$dbHost", "$dbUser") or die ("Error connecting to database.");

mysql_select_db("$dbDatabase", '$db') or die ("Couldn't select the database.");
$result = mysql_query(select * from users where username='$user' AND password='$pass', '$db');

//check that at least one row was returned

$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result)){

//start the session and register a variable

session_start();
$_SESSION('$user');

//successful login code will go here...
echo 'Success!';

//we will redirect the user to another page where we will make sure they're logged in
header( "Location: check.php" );

}

}
else {

//if nothing is returned by the query, unsuccessful login code goes here...

echo 'Incorrect login name or password. Please try again.';
}
} ob_flush(); ?>

Reply With Quote
  #11  
Old February 22nd, 2003, 08:27 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
first I would recomend that you put session_start(); at the very beginning of the code...
second, I would recomending using ob_flush(); before you redirect... IE:
PHP Code:
echo "Success!";
ob_flush();
header("Location: check.php"); 


Also.. change $_SESSION('$user'); to $_SESSION['$user'];
Square brackets indicate an array..

see if that helps.

Reply With Quote
  #12  
Old February 22nd, 2003, 11:28 AM
skatablaze skatablaze is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: cincinnati
Posts: 8 skatablaze User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to skatablaze
the idiot is back again!

the error:
Parse error: parse error, unexpected T_STRING in \welcome.php on line 51


always points to this line:

$result = mysql_query(select * from users where username='$user' AND password='$pass', '$db');


sorry for bothering you justin but i am not the brightest crayon in the box.

Reply With Quote
  #13  
Old February 22nd, 2003, 12:18 PM
huezer huezer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 1 huezer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i am a complete noobie with php. i have an FTP server host that i rent from. it has apache on it i suppose, but i am unaware if it has mysql. this article is intended for noobies such as myself, however it just jumps straight into the mysql stuff without explainin it! ;o Can someone please help me get on the right track? i.e. what i have to do to get to the mysql user db thing or w/e...... IM SO LOST!

Reply With Quote
  #14  
Old February 22nd, 2003, 12:38 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Re: the idiot is back again!

Quote:
Originally posted by skatablaze
the error:
Parse error: parse error, unexpected T_STRING in \welcome.php on line 51


always points to this line:

$result = mysql_query(select * from users where username='$user' AND password='$pass', '$db');


sorry for bothering you justin but i am not the brightest crayon in the box.


You aren't bothering me I like helping, makes me feel like I'm doing something good.. I figured out what the problem is with your result statment

change it from
Code:
$result = mysql_query(select * from users where username='$user' AND password='$pass', '$db');

to this:
Code:
$result = mysql_query("select * from users where username='$user' AND password='$pass'");

Or, you could do something like this as well, it makes it a little easier to read..
Code:
$strQuery = "select * from users where username='$user' AND password='$pass'";
$result = mysql_query($strQuery);


Sorry I didn't catch it earlier, the two things that could be botching that line up are: the fact that you didnt have the query in quotes.. tried it myself and got that same error and the fact that you have '$db' at the end of your query, you don't need that because you're already selecting the database when you did the mysql_select_db("$dbDatabase", '$db') or die ("Couldn't select the database."); statement... Try it, let me know if it works, k? I'm curious as to if that fixes it or not

PM Me if you need any more help, I'm glad to assist..

Reply With Quote
  #15  
Old February 22nd, 2003, 09:03 PM
skatablaze skatablaze is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: cincinnati
Posts: 8 skatablaze User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to skatablaze
i am still getting these errors please assist me in getting them right.

if you need the current code im trying to work with please email me at shorty40@fuse.net thanks for the help.


Warning: session_start() [function.session-start]: open(/tmp\sess_d611333baf5d5510a085ce214ff7ffe1, O_RDWR) failed: No such file or directory (2) in C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php on line 22

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php:9) in C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php on line 22

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php:9) in C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php on line 22

Notice: Undefined index: username in C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php on line 37

Notice: Undefined index: password in C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php on line 38

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\Documents and Settings\UserX001\My Documents\My Webs\welcome.php on line 51
Couldn't select the database.
Warning: Unknown(): open(/tmp\sess_d611333baf5d5510a085ce214ff7ffe1, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

Reply With Quote
  #16  
Old February 22nd, 2003, 10:58 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 16
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
Quote:
Originally posted by huezer
i am a complete noobie with php. i have an FTP server host that i rent from. it has apache on it i suppose, but i am unaware if it has mysql. this article is intended for noobies such as myself, however it just jumps straight into the mysql stuff without explainin it! ;o Can someone please help me get on the right track? i.e. what i have to do to get to the mysql user db thing or w/e...... IM SO LOST!


read Bens article PHP nad MySQL: The Basics. I believe it will help you a great deal
__________________
CHornJr
"One day I'll know what I am doing"
My Blog
Suanhacky Lodge #49
Rebel Squadrons

Reply With Quote
  #17  
Old March 10th, 2003, 12:48 PM
Frosty Frosty is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 1 Frosty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Please excuse my ignorance in the matter, but seeing as this is only my 2nd venture into PHP, I'm stuck on an issue...

The script works great initially, but after returning from the logout page and trying to log in again, I receive this error:

Warning: Cannot add header information - headers already sent by (output started at c:\inetpub\phpdev\login.php:49) in c:\inetpub\phpdev\login.php on line 52

I don't really know what to do. I tried ob_flush() but that just returned a 'no buffer' error.

What can I do?

- Frosty

Reply With Quote
  #18  
Old March 10th, 2003, 01:20 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Quote:
Originally posted by Frosty
Please excuse my ignorance in the matter, but seeing as this is only my 2nd venture into PHP, I'm stuck on an issue...

The script works great initially, but after returning from the logout page and trying to log in again, I receive this error:

Warning: Cannot add header information - headers already sent by (output started at c:\inetpub\phpdev\login.php:49) in c:\inetpub\phpdev\login.php on line 52

I don't really know what to do. I tried ob_flush() but that just returned a 'no buffer' error.

What can I do?

- Frosty

Frosty:

Put ob_start(); at the very beginning of the page, just after the opening <?php line.. ie:
PHP Code:
<?php
ob_start
();

//your code goes here
ob_flush();
?>


Hope that helps.

Reply With Quote
  #19  
Old March 19th, 2003, 12:40 AM
ravenboy ravenboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Albuquerque, NM, USA
Posts: 1 ravenboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i found it helpful

for some reason, your article helped me understand the process of protecting my pages better.

now that I know what the basic format is, I can go back and learn how to do the session stuff right!

thank you.

Reply With Quote
  #20  
Old April 5th, 2003, 08:40 AM
DJtm DJtm is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 DJtm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have a little problem with this script...

The login works perfectly, the problem is with the $user variable...

After login, i have put this in index.php:

<?php if(session_is_registered('user')){ echo 'You are logged in as $user'; } else { echo '<form name="form1" method="post" action="login2.php">

This only prints out:

You are logged in as $user


Not

You are logged in as DJtm

as it should....

What is wrong?

Reply With Quote
  #21  
Old April 5th, 2003, 09:30 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Quote:
Originally posted by DJtm
I have a little problem with this script...

The login works perfectly, the problem is with the $user variable...

After login, i have put this in index.php:

<?php if(session_is_registered('user')){ echo 'You are logged in as $user'; } else { echo '<form name="form1" method="post" action="login2.php">

This only prints out:

You are logged in as $user


Not

You are logged in as DJtm

as it should....

What is wrong?


The reason why it is doing this is because of the
PHP Code:
echo 'You are logged in as $user'

Change the single quotes to doubles.. so it should be
PHP Code:
echo "You are logged in as $user"


The single quotes will escape the $ and treat it as text

My recomendation would be to use double quotes except when neccesary... and just escape the quotes when you need them in your text

Reply With Quote
  #22  
Old April 18th, 2003, 11:46 AM
Mortal Mortal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 2 Mortal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi!
I'm not having much luck with this code. I'm pretty accomplished at Cold Fusion but so far I'm finding that PHP is not as easy.

No matter what I enter on the login.htm page (right user/pass, bad user/pass, no user/pass), login.php thinks I'm trying to access it directly.
Any suggestions?
FIXED! I just removed that code
I'd still like a solution if anyone knows though.

Question #2:
Simular to DJtm's question above, I was trying to show the user's name like below
PHP Code:
if(session_is_registered('username')){ 
echo 
"Welcome $username, you are still logged in. <br> <a href=login.htm>Go to Login Page</a>"


But it's unable to pull the variable:
Quote:
Notice: Undefined variable: username in D:\Web\php\phpplay\checklogin.php on line 12

Last edited by Mortal : April 18th, 2003 at 12:29 PM.

Reply With Quote
  #23  
Old April 18th, 2003, 12:46 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
do this before the
PHP Code:
if(session_is_registered('username')){ 
echo 
"Welcome $username, you are still logged in. <br> <a href=login.htm>Go to Login Page</a>"


put
PHP Code:
 $username $_POST['username']; 
and see if that works

Reply With Quote
  #24  
Old April 18th, 2003, 01:21 PM
Mortal Mortal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 2 Mortal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the quick reply!
I tried what you suggested and and even nastier message. I turned "register_globals" on but I still get the "undefined variables" error. No big deal just playing around with it.

I think it might have to do with how the sessions are set like JEB mentioned earlier.

Quote:
Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

Reply With Quote
  #25  
Old April 18th, 2003, 01:49 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
More than likely you're right

Reply With Quote
  #26  
Old June 6th, 2003, 06:50 AM
Cyril Cyril is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 Cyril User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Thanks for the code.

I had to add a couple of lines to get things to work as the author intended.

I appreciate that the code has attracted some criticism but I am very grateful for the initial code since it gave me a good starting point and clearly was the catalyst to bring forth all the 'solutions'.

Good thing all around

Reply With Quote
  #27  
Old June 6th, 2003, 06:08 PM
JDM71488 JDM71488 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 1 JDM71488 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to JDM71488
Success!
Warning: Cannot modify header information - headers already sent by (output started at /home/jdm71488/public_html/login.php:39) in /home/jdm71488/public_html/login.php on line 42

I get this when I try to log in (sometimes I will log in to see if it works and how it looks, because I am still constructing, then go back to my home page, and log in again after I make changes and I get this, if I close my browser and bring it up again it will work fine, but I dont want to do that every time)... I dont know what it means, how can I fix it??? Also when I try to log out... I just get a blank page how can I get that to send me back to my home page after it logs out? From reading the past comments, I know the code is out of date, and not right. But it gave me a pretty good understanding... How can I fix these problems??? Please help...

JDM

Reply With Quote
  #28  
Old June 8th, 2003, 12:31 PM
Cyril Cyril is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 Cyril User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Have you tried commenting out the line...

//successful login code will go here...
// cwk commented out to stop triggering of header output
// which gives rise to 'headers already sent' error
// echo 'Success!';


//we will redirect the user to another page header( "Location: checkLogin.php" );

Reply With Quote
  #29  
Old June 8th, 2003, 12:32 PM
Cyril Cyril is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 Cyril User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sorry but the last post came out wrong
the header line still needs to be commented in (of course)

//we will redirect the user to another page
header( "Location: checkLogin.php" );

Reply With Quote
  #30  
Old June 12th, 2003, 06:09 PM
dfano dfano is offline
Always Learning (I Think)
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: NYC Baby!!!!
Posts: 123 dfano User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to dfano Send a message via Yahoo to dfano
i am having a similar problem

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site33/fst/var/www/html/login.php:9) in /home/virtual/site33/fst/var/www/html/login.php on line 13

i am using the exact code that is in the article.

Thanks in advance,

Dave

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Discussion: PHP for Beginners by a Beginner: Simple Login, Logout, and Sessio


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap