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

Post Reply
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

set session?

Post by jayson.ph »

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

Code: Select all

$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
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: set session?

Post by social_experiment »

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

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
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: set session?

Post by jayson.ph »

[text]Avoid using session_register();[/text]

Why?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: set session?

Post by social_experiment »

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
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: set session?

Post by jayson.ph »

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

Re: set session?

Post by jayson.ph »

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
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: set session?

Post by social_experiment »

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
Post Reply