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
at a point, i have to login twice into my page, for some reason.
Old 10-28-2009, 08:08 PM at a point, i have to login twice into my page, for some reason.
Webmaster Talker

Posts: 611
Trades: 0
hi, when i have the login script at a certain point, and the address bar says "http://derekvanderven.com/mainsite.php?logoff=y" when i try to login right after that, i cant, and then the next time after that it works, making me login twice after i logout every time. any help getting rid of this greatly appreciated. thanks. derek.

here is the login page code

Code:
<?php
include("connect1.php");

session_start(); // this is the session declaration , one per page.
/// data is set up in the mysql lite table , rows are 
// record_id, int, 11, not null checked, default, null
//username, varchar, 20, default null
// password, varchar, 20 default, null
//Name, varchar, 20 default null
////////////////////////////////////////
////////////////////////////////////////
// a while loop is used to loop through and display output, like a table info, etc.dynamic rows.
$u = trim($_POST['username']);
$p = trim($_POST['password']); //trim makes it possible to have spaces around the passsword and user when typing it in.

$logoff = $_GET['logoff']; // this catches the logoff variable and value from the old.mainsite.php page.
$hack = $_GET['hack']; /// we got the hack variable from other page with GET

 
 

// if logoff is set, destroy the session, or unset it.
if($logoff){

    
    unset($_SESSION['userid']);
    
    session_destroy();

    $message = "You have been logged off"; // notice here that he used the same variable as before but just changed value

    
     

            }

  
if($hack){    

    $message = "Naughty Naughty!"; // COOL

    }
 
 


// if fields username and password have contents, then...
if($u && $p){
    
    $query = mysql_query("SELECT * FROM table2 WHERE username = '$u' AND password = '$p'");

    $result = mysql_fetch_array($query); //creates array called result,//notice we dont need a while loop here.
                                          //if its found a user it will create a populated array, if find nothing, it creates a blank array.
                                            //the mysql_fetch_array automatically gives us our keys for us.
    if($result['username']){ // if username is set, go on...username is a key for $result, and a field in the table.
        
        $message = "You have been logged in";
        // session is an array, a php defined word, becomes like a variable.which can be accessed on any page.
        // 'userid'here is like a variable. we are going to assign to $_SESSION whatever the $result array contains which is 'username' in this case.
        
        $_SESSION['userid'] = $result['username'];
    
        header("Location:old.mainsite.php"); // this will redirect them to the application.php page. and exit the script here.
        exit;
    
    
    }else{
        
        $message = "You do not exist on the system";
        
    }
    
    

}
?>
and here is the old.mainsite.php code

Code:
<?php
include("connect1.php");
include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man. ooooh.






?>
and
Code:
<a href="mainsite.php?logoff=y" class="style16">Logoff</a>
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-29-2009, 08:15 AM Re: at a point, i have to login twice into my page, for some reason.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,516
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
comment out
PHP Code:
<a href="mainsite.php?logoff=y" class="style16">Logoff</a
and see if it still happens
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-29-2009, 09:09 AM Re: at a point, i have to login twice into my page, for some reason.
spyderwebtech's Avatar
Skilled Talker

Posts: 51
Trades: 0
When you logout and your url has the "?logoff=y" in it then that GET variable is still passed onto the login script (which is confirmed via Firebug).

In your login script there is a piece of code that that checks for that logoff variable and if so destroys the session!
Code:
if($logoff){

    
    unset($_SESSION['userid']);
    
    session_destroy();

    $message = "You have been logged off"; // notice here that he used the same variable as before but just changed value

    
     

            }
read what session_destroy does..

http://php.net/manual/en/function.session-destroy.php

so basically when you try to reset the session variable.. there is no session instance. You have to recall session_start()
spyderwebtech is offline
Reply With Quote
View Public Profile
 
Old 10-29-2009, 11:55 AM Re: at a point, i have to login twice into my page, for some reason.
Webmaster Talker

Posts: 611
Trades: 0
thank you both. what i did was i commented the session destroy line, and it works fine now. is there some security hole now , now that i did that? im not sure. but the script seems to work, i just dont know if a hacker can get in now that the session isnt destroyed. thanks very much. derek
silverglade is offline
Reply With Quote
View Public Profile
 
Old 10-29-2009, 11:59 AM Re: at a point, i have to login twice into my page, for some reason.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,516
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A session only exists between the server and the browser you have just been using on your machine.

If you were using two different browsers on your machine you would have TWO sessions open
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-29-2009, 12:11 PM Re: at a point, i have to login twice into my page, for some reason.
spyderwebtech's Avatar
Skilled Talker

Posts: 51
Trades: 0
Like Chris says...
Quote:
A session only exists between the server and the browser you have just been using on your machine.
by commenting out the session_destroy() a hacker still would not be able to easily hijack the sessions.

I would be extremely worried about SQL injections though..... all that script does is trim the input

ALWAYS use mysql_real_escape_string() on the input before you use it in a sql statement
spyderwebtech is offline
Reply With Quote
View Public Profile
 
Old 10-29-2009, 12:17 PM Re: at a point, i have to login twice into my page, for some reason.
Webmaster Talker

Posts: 611
Trades: 0
thanks both again. i will look into preventing those sql injections. my target audience probably doesnt have a clue about computers but you never know. im just glad im not hosting a programming site. HAHA. thank you both VERY much. my script is working great now! thank you . derek
silverglade is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to at a point, i have to login twice into my page, for some reason.
 

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.27399 seconds with 12 queries