Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 16-06-2002, 10:29 AM
rix's Avatar
rix rix is offline
Novice Webmaster
 
Join Date: Jun 2002
Location: Subang Jaya
Posts: 25
Rep Power: 0
rix is on a distinguished road
Send a message via Yahoo to rix
session management

saya dah try banyak kali la jugak pasal session ni, tapi sendiri pon tak tau camner nak tau session tu working atau tak

Last edited by rix; 17-06-2002 at 02:08 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 17-06-2002, 04:31 AM
rix's Avatar
rix rix is offline
Novice Webmaster
 
Join Date: Jun 2002
Location: Subang Jaya
Posts: 25
Rep Power: 0
rix is on a distinguished road
Send a message via Yahoo to rix
aku dah buat page ni, tapi tak sure session jadi ke tak. bawah ni code yg aku buat

1. authmodule.php
PHP Code:
function ulogin() {
?>
<form action="main.php" method="POST">
  Username &nbsp;:<input type="text"     name="username" class="normaltxt"><br>
  Password &nbsp;:<input type="password" name="password" class="normaltxt"><br>
  <input type="Submit">
</form>
<?
}
?>
2. forum.php
PHP Code:
<?
function forum() {
if (
$usertype == "admin") {
    print 
"admin login at forum"; }
    elseif (
$usertype == "user") {
        print 
"user login at forum"; }
        elseif (
$usertype == "guess") {
            print 
"guess login"; }
            else { print 
"no usertype set"; }

}
3. main.php
* b4 aku implement dalam mysql, try login n password in clear text dulu la kan :P
PHP Code:
<?
session_start
(); 
error_reporting(1);
if (
$username == "rix" && $password == "a") {
    
$usertype "user";
    
session_register($usertype);
    

?>
<html>
<head>
<title>session test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?

require "./script/authmodule.php";
require 
"./script/forum.php";
switch (
$status) {
    case 
'login' :
     
ulogin();
    break;
    
    case 
'forum' :
    
forum();
    break;
    
    default:
    if (
$usertype == "admin") { 
        print 
"admin page"
    } elseif (
$usertype == "user") { 
        print 
"user"
    } else { print 
"usertype is guess"; }
    break;
}
include 
'footer.inc' 
    
?>
</body>
</html>
page main.php kalau masuk biasa dier akan keluar "usertype is guess", bila dah submit kat form ulogin tu, dier keluar "user" kat main. tapi bila bukak url sama kat IE baru, dier keluar guess.. so saya rasa session tu berjalan la kot. tapi timbul masalah baru, camner nak bawak $usertype ke semua file php cam bile pi kat forum. dier detect as user bukan guess pasal dah login.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 17-06-2002, 04:11 PM
Novice Webmaster
 
Join Date: Nov 2001
Location: JHR
Posts: 89
Rep Power: 86
r0kawa is on a distinguished road
Send a message via Yahoo to r0kawa
nak buat available kat semua page

cuma perlukan

session_start();
session_register('USER');


Jangan buat benda tu jadi variable, tetapi isi dia yang variable
sekarang ni , contohnya. aku amik data dari database utk user.

if($login)
//for login di hantar
{

$sql = mysql_query("select * from passwd_table where id='$username' and password='$password'");
if($data = mysql_fetch_array($sql);
$USER = $data;
}

else {
$USER = "GUEST";
}


} //END IF($LOGIN)

errr... macam advance pulak, tapi cuba la baca2 manual dia ke
__________________
<a href="http://www.php.net.my">www.php.net.my</a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 18-06-2002, 07:09 PM
rix's Avatar
rix rix is offline
Novice Webmaster
 
Join Date: Jun 2002
Location: Subang Jaya
Posts: 25
Rep Power: 0
rix is on a distinguished road
Send a message via Yahoo to rix
thanks for explaining

aku surfing gak pasal session manager ni dan at last aku paham camner nak start session, tapi tok orang yg tak tau, session ni bole start dalam 2 cara

cara 1:
start pakai session_start() lepastu bile nak register value supaya semua page bole pakai, kena pakai session_register($var).

cara 2: terus pakai session_register($var), nanti dia akan start session and register terus variable tu.

ade 2 cara ni, speed wise, mmg takder beza cuma cara orang coding, kalau pakai cara 1 dier cam tersusun coding pasal ade starter, cara 2 plak dier start tapi cam hiding sikit so nampak cam ko settle math equation skip 1 langkah :P
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is the best Cyber Cafe Management Software ? Richland Mamak Stall 8 08-07-2008 11:14 PM
Reseller Required for Web Content Management Solution !!! Larkspur Other Webmaster-related Services and Promotion 0 14-11-2005 02:47 PM
Web Content Management ? eyeball Website Programming 8 19-09-2005 12:00 PM
stockbroker risk management riskofinaction Other Webmaster-related Services and Promotion 0 09-11-2004 04:31 PM
Building management game... Syazwan Website Programming 2 08-12-2003 12:44 AM



All times are GMT +8. The time now is 03:02 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59