Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problems with sessions....
Old 03-30-2005, 05:07 PM Problems with sessions....
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
hey

Im trying to create a login script using sessions, ive got a documentation about sessions and it all seemed pretty straight forward, but im having trouble with it not recognising the session stored variable in other scripts. Below is the code im using...

Login Page:

PHP Code:
<?php

    session_start
();

include(
"admin_setup.php");

include(
"admin_colour_scheme.php");

include(
"admin_top.php");

include(
"admin_login_sidelinks.php");

?>


///HTML omitted


if(isset($_GET['team_id'])){
    
//code omitted showing log in screen text boxes etc if form not processed yet

} elseif(isset($_POST['username'])&& isset($_POST['password']) && isset($_POST['team_id'])) {
    
    $username_submit = $_POST['username'];
    $password_submit = $_POST['password'];
    $team_id_submit = $_POST['team_id'];
    
    $result = mysql_query("SELECT * FROM account WHERE id='$team_id_submit'");
    
    $num_rows = mysql_num_rows($result);
    
    $result_rows = mysql_fetch_array($result);
    
    $name = $result_rows['name'];
    $username = $result_rows['username'];
    $password = $result_rows['password'];
    
    
    if(($username == $username_submit) && ($password == $password_submit)) {
            
    
    session_register("logged_on");

    
    $logged_on = "1";

    print "Welcome $name, You've successfully logged into your Team Lines Admin Centre";
    print "<br>";
    print "<br>";
    print "You will be redirected to the Admin Centre in 5 seconds...";
    print "<br>";
    print "<br>";
    print "or click <a href=\"admin_account.php?team_id=$team_id_submit\">here</a> to proceed to the Admin Centre";
    
} else {
    
    print "Sorry, but the Username and/or Password you supplied was incorrect.  Please go <a href=\"javascript:history.back(-1)\">back</a> and try again.";
    
}    
    
}

?>

Checking if user is logged in on admin pages...
PHP Code:
<?php
session_start
();
    
    if(
$logged_on == "0"){
        
        
header"Location: login.php?team_id=$team_id");
    }
    
?>

I hope this makes sense to someone at least, and i appreciate any comments.

Cheers
Stoot

PS im using PHP v 4.3.3 and Apache 1.3.27 if maybe i have settings to change.
stoot98 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-30-2005, 05:18 PM
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
Quote:
Originally Posted by stoot98
if($logged_on == "0"){
I think that here you should rather use here HTTP_SESSION_VARS table, so there should be:
Code:
if ($HTTP_SESSION_VARS['logged_on']=="0")
{
but I have to add, that I'm not sure because I use only new sessions' methods ($_SESSION and session_start) and I don't use old methods ($HTTP_SESSION_VARS and session_register).

However, I hope that my advice will help you...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Old 03-30-2005, 05:49 PM
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Thanks for the reply. You mentioned that you use 'new methods' as apposed to the 'old ones' im learning from an old..ish book so is there any chance you could tell me where and how i would use the 'new methods' to replace the ones i have used.

Cheers
Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 04-02-2005, 04:59 AM
pitbull82's Avatar
Super Talker

Posts: 147
Name: Marcin Nabiałek
Location: Poland, Częstochowa
Trades: 0
You can do that very simple.

In the first file you change
Code:
    
session_register("logged_on");    
$logged_on = "1";
into

Code:
$_SESSION['logged_on']="1"

and in the second file you should use:

Code:
<?php
session_start();
    
    if(isset($_SESSION['logged_on'] && $_SESSION['logged_on'] == "0"){
        
        header( "Location: login.php?team_id=$team_id");
    }
    ?>
Notice that when you use those "new" methods, I mustn't use the old ones in the same time and if you do it, many strange errors can occur...

For more information look into PHP manual...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
pitbull82 is offline
Reply With Quote
View Public Profile Visit pitbull82's homepage!
 
Reply     « Reply to Problems with sessions....
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13674 seconds with 12 queries