set session?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

set session?

Postby jayson.ph » Sun Jun 17, 2012 9:05 pm

hi all,

i have code for login.php below and it work okay and i get in. but my problem now is where should i put the session code to start and to destroy it:
into page: branch_view.php or
here in login.php
Syntax: [ Download ] [ Hide ]
$pingsql = "SELECT * FROM tbl_user WHERE usr_name = '$valusename' AND usr_pass = '$valpasswrd'";
        $pingresult = mysql_query($pingsql);
        $pingrowscount = mysql_num_rows($pingresult);
        if($pingrowscount == 1)
        {
        session_register('usr_name');
        session_register('usr_pass');
        header('Location:../public-functions/branch_view.php');
        }
        else
        {
        header('Location:../login_function/error_login_function/logerror.php');


Please help
User avatar
jayson.ph
Forum Contributor
 
Posts: 165
Joined: Mon Jan 02, 2012 10:20 am
Location: MP

Re: set session?

Postby social_experiment » Mon Jun 18, 2012 12:40 am

session_start() always goes at the top of the page;

http://forums.devnetwork.net/viewtopic.php?f=28&t=135287
Have a look at this tutorial about where to regenerate a new and destroy the old session. Avoid using session_register();
The Manual wrote:This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
social_experiment
DevNet Master
 
Posts: 2775
Joined: Sun Feb 15, 2009 12:08 pm
Location: .za

Re: set session?

Postby jayson.ph » Mon Jun 18, 2012 1:01 am

Syntax: [ Download ] [ Hide ]
Avoid using session_register();


Why?
User avatar
jayson.ph
Forum Contributor
 
Posts: 165
Joined: Mon Jan 02, 2012 10:20 am
Location: MP

Re: set session?

Postby social_experiment » Mon Jun 18, 2012 1:16 am

It's deprecated as of php 5.3 meaning it is no longer used by php. If you use it and the code is on a server running php 6 the variables won't be registered
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
social_experiment
DevNet Master
 
Posts: 2775
Joined: Sun Feb 15, 2009 12:08 pm
Location: .za

Re: set session?

Postby jayson.ph » Mon Jun 18, 2012 1:27 am

Ah Okay Thank you for the information.
User avatar
jayson.ph
Forum Contributor
 
Posts: 165
Joined: Mon Jan 02, 2012 10:20 am
Location: MP

Re: set session?

Postby jayson.ph » Mon Jun 18, 2012 1:35 am

one question please, i already set session_destroy but somehow when i click back button from the browser. i get in without signing in into log-inform. why? what should i use?
User avatar
jayson.ph
Forum Contributor
 
Posts: 165
Joined: Mon Jan 02, 2012 10:20 am
Location: MP

Re: set session?

Postby social_experiment » Mon Jun 18, 2012 2:08 am

what does the code that checks if a user is logged in look like
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
social_experiment
DevNet Master
 
Posts: 2775
Joined: Sun Feb 15, 2009 12:08 pm
Location: .za


Return to PHP - Code

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 13 guests