473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

session handling

lak
I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.
Aug 29 '08 #1
7 1503
lak wrote:
I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.
I'm not sure what you're looking for. Basic session handing is quite
simple - at the start of any page which uses sessions call
session_start(), before ANY output is sent to the browser. After that,
just set values in the $_SESSION[] array and later retrieve them from
the $_SESSION[] array. PHP handles the rest.

Of course, if you want to get into custom session handlers, that gets a
bit more complicated.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 29 '08 #2
On Aug 29, 10:14*am, lak <lakindi...@gmail.comwrote:
I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.
http://php.net/session
Aug 29 '08 #3
I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.
If you haven't discovered it yet, phonet is one of the best resurces
around for anything to do with PHP et al. Try http://php.net/session
for one, and then there is a lot of info at w3schools too.
If you become familiar with those sites you'll have a wealth of
startup information and more available to you.

HTH

Aug 29 '08 #4
lak wrote:
>I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.

I'm not sure what you're looking for. Basic session handing is quite
simple - at the start of any page which uses sessions call
session_start(), before ANY output is sent to the browser. After
that, just set values in the $_SESSION[] array and later retrieve
them from the $_SESSION[] array. PHP handles the rest.

Of course, if you want to get into custom session handlers, that gets
a bit more complicated.
But J, it's not very simple to a beginniner. In fact, just the phrase
"before any output is sent to the browser" can create some lengthy
conversations for those who don't yet have experience in that area.
Even Hello World programs take a certain amount of introduction for
newbies to PHP.

Why is it you chose to not respond to his question but instead made
vague generalized statements?

I'm curious.

Twayne
Aug 29 '08 #5
On Fri, 29 Aug 2008 06:14:06 -0700 (PDT), lak <la********@gmail.com>
wrote:
>I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.
I'm a PHP newbie like you, but here's some working code to give you an
idea:

Add this to every page that is off-limit to non-authorized users:

<? // Has a session already been created? If not, create new one
if($PHPSESSID)
session_start($PHPSESSID);
else
session_start();
?>

Here's how to manipulate data that are part of a session:
<? session_register("email"); ?>
<? $email="me@acme.com"; ?>
<? echo $email; ?>
<? session_unregister("email"); ?>
<? session_destroy(); ?>

Here's how to extract information form a session table:
$sql = "select user_id,status,date_created from session where
id='" . $PHPSESSID . "'";
$result = @mysql_query($sql) or
die('Query failed: ' . mysql_error());

$row = mysql_fetch_row($result);
echo "user_id = " . $row[0] . "<p>";
echo "status = " . $row[1] . "<p>";
echo "date_created = " . $row[2] . "<p>";

If most data are common to all users, a smarter way is to keep
user-specific data in sessions, but keep
common data in a cache (APC, MemCacheD, etc.):
session_start();
if(isset($_SESSION['myprivatevalue'])) {
print $_SESSION['myprivatevalue'] . "<p>\n";
} else {
$_SESSION['myprivatevalue'] = "verysecret";
}

//apc_add('scooby-doo', 'daphne');
print "Scooby-do=" . apc_fetch('scooby-doo');
//apc_delete('scooby-doo');

http://www.tizag.com/phpT/phpsessions.php

HTH,
Sep 1 '08 #6
..oO(Gilles Ganault)
>On Fri, 29 Aug 2008 06:14:06 -0700 (PDT), lak <la********@gmail.com>
wrote:
>>I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.

I'm a PHP newbie like you, but here's some working code to give you an
idea:
Some notes about this "working" code:
>Add this to every page that is off-limit to non-authorized users:

<? // Has a session already been created? If not, create new one
Avoid short open tags. They are completely unreliable and will most
likely be turned off by default in the coming PHP 6.
if($PHPSESSID)
Where is $PHPSESSID coming from? And why are you interpreting it as a
boolean?
session_start($PHPSESSID);
else
session_start();
?>

Here's how to manipulate data that are part of a session:
<? session_register("email"); ?>
session_register() is deprecated and not necessary anymore.
<? $email="me@acme.com"; ?>
<? echo $email; ?>
<? session_unregister("email"); ?>
Same here. Just drop it.
<? session_destroy(); ?>
And why all the <? ... ?>? Why not simply a single <?php ... ?block?

To summarize all the above:

<?php
session_start();
$_SESSION['email'] = 'm*@example.com';
?>

That's it. Then on another page:

<?php
session_start();
if (isset($_SESSION['email'])) {
print $_SESSION['email'];
}
?>

Or something like that.
>Here's how to extract information form a session table:
$sql = "select user_id,status,date_created from session where
id='" . $PHPSESSID . "'";
The next problem. Even a session ID should be handled with care and be
seen as a potential threat. _Never_ trust anything coming in from the
client! The keyword here is "SQL injection".

Micha
Sep 1 '08 #7
Gilles Ganault wrote:
On Fri, 29 Aug 2008 06:14:06 -0700 (PDT), lak <la********@gmail.com>
wrote:
>I want to study about the Session handling in PHP. I don't know where
to start. So please suggest me some way.

I'm a PHP newbie like you, but here's some working code to give you an
idea:

Add this to every page that is off-limit to non-authorized users:

<? // Has a session already been created? If not, create new one
if($PHPSESSID)
session_start($PHPSESSID);
else
session_start();
?>

Here's how to manipulate data that are part of a session:
<? session_register("email"); ?>
<? $email="me@acme.com"; ?>
<? echo $email; ?>
<? session_unregister("email"); ?>
<? session_destroy(); ?>

Here's how to extract information form a session table:
$sql = "select user_id,status,date_created from session where
id='" . $PHPSESSID . "'";
$result = @mysql_query($sql) or
die('Query failed: ' . mysql_error());

$row = mysql_fetch_row($result);
echo "user_id = " . $row[0] . "<p>";
echo "status = " . $row[1] . "<p>";
echo "date_created = " . $row[2] . "<p>";

If most data are common to all users, a smarter way is to keep
user-specific data in sessions, but keep
common data in a cache (APC, MemCacheD, etc.):
session_start();
if(isset($_SESSION['myprivatevalue'])) {
print $_SESSION['myprivatevalue'] . "<p>\n";
} else {
$_SESSION['myprivatevalue'] = "verysecret";
}

//apc_add('scooby-doo', 'daphne');
print "Scooby-do=" . apc_fetch('scooby-doo');
//apc_delete('scooby-doo');

http://www.tizag.com/phpT/phpsessions.php

HTH,
Or simply get the correct code here:
http://www.php.net/manual/en/book.session.php

Pretty explanatory there.
Sep 1 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sean Pinto | last post by:
Ok, you all are going to have to bear with me on this one as it is kinda complicated to explain. I am implementing a company management suite that requires Role-Based authentiations (ie. users are...
3
by: news.onet.pl | last post by:
Hello I'm biting into the following problem: HTTP is stateless protocol and thus net languages' designer had to find out session. As far as I know session handling in any of the language (PHP,...
3
by: Richard P | last post by:
I am experiencing some browser weirdness. My app uses session state to hide values I prefer to keep out of the querystring. I am testing to see what happens when cookies are fully disabled in IE...
9
by: Marcus | last post by:
Hello, Currently all of my php pages use SSL, not just my initial login. Originally I thought this would be more secure, but after thinking about things and looking at sites like Amazon and...
0
by: TaeHo Yoo | last post by:
Hi all, I am prett new in asp.net. We have a project which has classic asp and asp.net scripts. Obviously this project has a bin directory under the root directory. About 80% of this project...
1
by: Oscar Thornell | last post by:
Hi, I have an ASP.NET page that generates an Exception... The Exception is not caught in the executing method...so it propagates to..the Page_Error event handling method.. In that method the...
4
by: John Allberg | last post by:
Hi! We have a problem which is correlated to web farms and session handling and are thinking of what solution to choose. Our setup is with a web farm, one ldap server and a database cluster. ...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
9
by: viz | last post by:
hi, i have written a class for session handling, and i want to use it to keep track of the user. After authenticating the user in login page i am storing the session info like uname etc.. in a...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.