PHP Sessions
#1
Video 
The Following Script Is example of the PHP sessions Function:
<?php
session_start();
// store session data
$_SESSION['views']=1;
?>

<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>

</body>
</html>
Reply
#2
(09-30-2011, 01:19 PM)manik90 Wrote:  The Following Script Is example of the PHP sessions Function:
<?php
session_start();
// store session data
$_SESSION['views']=1;
?>

<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>

</body>
</html>

its right code n algorithm. but i think pageview is not using $_SESSION. AFAIK pageview using database,

example.
PHP Code:
<?php

$page_id 
20;
$query "SELECT page_view FROM page WHERE id='$page_id'";
$data mysql_fetch_array(mysql_query($query));

$pageviews $data['page_view'];
$pageviews+=1;

$query "UPDATE page SET page_view='$pageviews' WHERE id='$page_id'";

?>

i think it for page view case.

this is for $_SESSION function in right case.

PHP Code:
<?php

session_start
();
$uname $_POST['username'];
$pass $_POST['password'];

$query "SELECT * FROM users WHERE username = '$uname' AND password = '$pass'";
$data mysql_num_row(mysql_query($query));

if (
$data 0$_SESSION['uname'] = $uname;

if (isset(
$_SESSION['uname']))
echo 
"Welcome back $_SESSION['uname']";
else
echo 
"Please Login";

?>

correct me if i'm wrong
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)