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>
#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:
1
2
3
4
5
6
7
8
9
10
11
12
<?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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?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



Forum Jump:


Users browsing this thread: 1 Guest(s)

Sponsors: FuzzyHosts - WeLoveServers - Ftpit - ZXPlay - BoneVM - GalaxyHostPlus - Kwicero LTD - Verelox- HostUS


BitCoin donations: 1DQxbstaTb5SWk6QC2gFeQUTFR64JX4cEo