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

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 23-09-2004, 03:44 PM
brutalasia's Avatar
Novice Webmaster
 
Join Date: Jul 2002
Location: ch3r4$ d4ruL 3h$4n
Posts: 26
Rep Power: 0
brutalasia is on a distinguished road
Send a message via Yahoo to brutalasia
Sape tau main ngan SESSION in PHP ??

Assalamu'alaikum wbr,

erm.. ada sesape ble tolong? harap sesangat nie ..
aku tengah develop satu sistem gune PHP..

tang login form aku dah create n success..
tapi aku tak gheti camne nak main ngan SESSION..

so, once login is success, aku redirect ke member's page..
dr situ aku nak view info but tak tau nak tarik ID dia..

harap ada sesape dpt membantu..

Wassalam.
__________________
-Kh4|if4H^4|4m^m4y4-
Akhirat=CAHAYA,Dunia=BAYANG2.
Bile kite kejar cahaya,otomatik bayang2 folo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 23-09-2004, 05:49 PM
brutalasia's Avatar
Novice Webmaster
 
Join Date: Jul 2002
Location: ch3r4$ d4ruL 3h$4n
Posts: 26
Rep Power: 0
brutalasia is on a distinguished road
Send a message via Yahoo to brutalasia
ok nie coding aku.

login.php

Code:
  <form action="logindo.php" method="POST">
    <table border="1">
      <tr bgcolor="#993399"> 
        <td colspan="2"> 
          <div align="center"><font color="#FFFFFF">Login</font></div></td>
      </tr>
      <tr> 
        <td width="114">Matrix Number</td>
        <td width="174">: 
          <input name="matrix_no" type="text" id="matrix_no" /></td>
      </tr>
      <tr> 
        <td>Password</td>
        <td>: 
          <input type="password" name="password" /> <input name="submit" type="submit" value="send" /></td>
      </tr>
    </table>
    [ <a href="register.php">register</a>? ] 
  </form>

logindo.php

Code:
<?php 
session_start(); 
error_reporting(E_ALL); 

// Connect to the database server 
$dbcnx = mysql_connect('localhost', 'root', '') 
             or die('<p>Unable to connect to the database server at this time.<br />Error: ' . mysql_error() . '</p>'); 

// Select the huh database 
mysql_select_db('profile') 
             or die('<p>Unable to locate the profile database at this time.<br />Error: ' . mysql_error() . '</p>'); 

$matrix_no = strip_tags(trim($_POST['matrix_no'])); 
$password = strip_tags(trim($_POST['password'])); 

$sql = "SELECT matrix_no, password, user_id 
          FROM userinfo 
         WHERE matrix_no = '$matrix_no' 
           AND password = '$password' 
         LIMIT 0,1"; 

$result = mysql_query($sql) 
             or die('<p>Unable to query the profile database at this time.<br />Error: ' . mysql_error() . '</p>'); 

$row = mysql_fetch_array($result); 
echo '<p>sql: ' , $sql , '<br />Matrix Number: ' , $row['matrix_no'] , '<br />Password: ' , $row['password'] , '</p>'; 

if(mysql_num_rows($result) == 1) // mysql_num_rows() returns the record count from the query result.  you want one (1) matching record to verify the login was successful. 
{ 
     $_SESSION['loggedin'] = 1; // Setting session var 'loggedin' to true 
	 $_SESSION['user_id'] = $user_id;
     header('Location:member.php'); 
     exit; 
} 
else 
{ 
     header('Location:error.php'); // Redirect to error page, as a matching record was not found in the table. 
     exit;  // always 'exit' 
} 
?>
login success...
erm... btul ke aku set session tu?
dan ape coding yg perlu aku letak tuk setiap page for registration user je yg ble xs?
__________________
-Kh4|if4H^4|4m^m4y4-
Akhirat=CAHAYA,Dunia=BAYANG2.
Bile kite kejar cahaya,otomatik bayang2 folo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 23-09-2004, 05:50 PM
lcf's Avatar
lcf lcf is offline
Pro-Blogger
 
Join Date: Feb 2003
Location: Kluang, Johor
Posts: 2,376
Rep Power: 115
lcf will become famous soon enough
Send a message via ICQ to lcf Send a message via MSN to lcf Send a message via Yahoo to lcf
have you refer official PHP manual for SESSION help? There are explaination and example of code inside.

You can get it from http://www.php.net
__________________
LiewCF | Malaysia Bloggers Forum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 24-09-2004, 10:28 AM
brutalasia's Avatar
Novice Webmaster
 
Join Date: Jul 2002
Location: ch3r4$ d4ruL 3h$4n
Posts: 26
Rep Power: 0
brutalasia is on a distinguished road
Send a message via Yahoo to brutalasia
erm.. still tak brape faham la..
ble bg contoh coding tak?

dan ape coding yg perlu diletakkan di awal page yg hanya registered user je ble view?
__________________
-Kh4|if4H^4|4m^m4y4-
Akhirat=CAHAYA,Dunia=BAYANG2.
Bile kite kejar cahaya,otomatik bayang2 folo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 24-09-2004, 02:12 PM
Novice Webmaster
 
Join Date: Sep 2004
Location: Shah Alam
Posts: 68
Rep Power: 50
infeeneetee is on a distinguished road
kena faham dulu konsep session..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 24-09-2004, 05:38 PM
Inspired Webmaster
 
Join Date: Jul 2004
Location: SJ, Selangor
Posts: 189
Rep Power: 54
vcheewei is on a distinguished road
i'll explain very very briefly here.

I assume that you already have a form for username and password which could be a html file. then when clicked on login the action should be pointing to a php file.
In the php file u will do this:
Firstly, check whether the username & password matched if yes
then u have to start a session.
Later, u have to create a session and store value into it.
next, on every page you must start with session_start(); (only for those pages that requires login).
after that, u put few lines of codes after the session_start() to check whether the session variable was having a value that you assigned during the first page (only for pages that requires login).
if there is value continue else die(); so that the page will not be displayed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 24-09-2004, 06:02 PM
mysticmind's Avatar
Super Moderator
 
Join Date: Jun 2001
Location: Mystic Kingdoms
Posts: 2,619
Rep Power: 141
mysticmind will become famous soon enough mysticmind will become famous soon enough
Send a message via Yahoo to mysticmind
Disini tutorial login, session dalam BM.
oleh sdr rokawa kalau tak silap..

Senang dan mudah difahami..
yang penting punyai ketajaman minda dan tahap sabar berusaha yang tinggi

http://www.php.net.my/211-Membina-ha...an-laluan.html
__________________
Personal's Blog! - Malaysian Artist!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 24-09-2004, 08:09 PM
brutalasia's Avatar
Novice Webmaster
 
Join Date: Jul 2002
Location: ch3r4$ d4ruL 3h$4n
Posts: 26
Rep Power: 0
brutalasia is on a distinguished road
Send a message via Yahoo to brutalasia
ok.. alhamdulillah.. session dah success..

ok la nie bile user dah success login.. akan ada satu button tuk apply hostel.. just satu list down je... then bila dia submit, failed la... data tak masuk dlm databse..

FYI, aku just create satu table je.. and now just nak update + masukkan field (hostel) tadi tu je.. nie coding aku :


apply.php
Quote:
<?php
session_start();
if (!$_SESSION[matrix_no])
{
print "<p align=center><font color=red>Access Denied</font></p>";
//header("Location:xs_denied.php");
include ("login.php");
}
else
{
?>
<html>
<head>
<title>Apply Hostel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><form name="form1" method="post" action="applydo.php">
<h1 align="center">Apply Hostel</h1>
<table width="217" border="0" align="center" cellspacing="0">
<tr>
<td width="98">Select hostel</td>
<td width="115">:
<select name="hostel" id="hostel">
<option value="-">-</option>
<option value="Perindu">Perindu</option>
<option value="Anggerik">Anggerik</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><br> <input type="submit" name="Submit" value="Submit"> <input type="hidden" name="hiddenField">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>
applydo.php
Quote:
<?php
session_start();

if (!$_SESSION[matrix_no])
{
print "<p align=center><font color=red>Access Denied</font></p>";
//header("Location:xs_denied.php");
include ("login.php");
}

else
{
?>
<html><title>Apply Hostel</title>
<body>
<?php
$conn = mysql_connect ("localhost", "root", "");
mysql_select_db ("profile", $conn);
//$sql = "UPDATE userinfo SET hostel = ($hostel) WHERE matrix_no=$_SESSION[matrix_no]";
//$sql="UPDATE userinfo SET hostel ='"$hostel"' WHERE matrix_no = '"$_SESSION'[matrix_no']"'";
$hostel = strip_tags(trim($_POST['hostel']));

$sql="UPDATE userinfo SET hostel = ($hostel) WHERE matrix_no = $_SESSION[matrix_no]";

if (mysql_query ($sql, $conn))
{
echo "<h1>Your application will be process!</h1>";

print ("<br><br>You'd apply hostel : <b>");
print ($hostel);
print ("</b>");

}
else
{ echo"<h1>something went wrong</h1> <br> <input type='button' value='Back' onclick=history.go(-1)>"; }
?>
</body>
</html>
<?php
}
?>
bile members click submit.. dia akan gi terus ke ELSE dan papar mesej something went wrong.
Harap dapat membantu..
__________________
-Kh4|if4H^4|4m^m4y4-
Akhirat=CAHAYA,Dunia=BAYANG2.
Bile kite kejar cahaya,otomatik bayang2 folo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 26-09-2004, 11:59 AM
Gemp-X's Avatar
Novice Webmaster
 
Join Date: Apr 2002
Location: kuantan, pahang
Posts: 58
Rep Power: 79
Gemp-X is on a distinguished road
Send a message via Yahoo to Gemp-X
check syntax, agak berterabur sket la

1)kalau array tu jangan lupe letak ( " ) atau ( ' ), takpe kalau tak letak pun PHP akan assumed. sebaiknye letak la

2)lagi, kalau kita nak letak array dalam string. kene letak { }
Code:
$sql="UPDATE userinfo SET hostel = '$hostel' WHERE matrix_no = '{$_SESSION['matrix_no']}'";
3)try to make your code clean & tidy

contohnye kalau dah guna "echo" , guna echo terus, takyah guna "print"

4)escape character ( \ ) jangan dilupakan
__________________
http://sidik.org/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 29-09-2004, 12:22 PM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 59
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
aku dah lama tak jenguk php ni.. dekat setengah tahun sbb sambg blaja. takde masa nk buat progg. tapi, kalau aku tak silap, kat applydo.php tu ko tak hold value yg ko pass dr prev page tuh.. kalau aku tak silap la.. kalau silap, sorry beb!
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 30-09-2004, 11:14 AM
brutalasia's Avatar
Novice Webmaster
 
Join Date: Jul 2002
Location: ch3r4$ d4ruL 3h$4n
Posts: 26
Rep Power: 0
brutalasia is on a distinguished road
Send a message via Yahoo to brutalasia
ok.. prob solve gak akhirnye..
fuh.. mencabar gak awal2 nak blaja nie..
aku tukar code jadi cam nie :

Code:
$sql="UPDATE userinfo SET hostel = '$hostel' WHERE matrix_no = $_SESSION[matrix_no]";
mekaseh atas perhatian anda semua..
__________________
-Kh4|if4H^4|4m^m4y4-
Akhirat=CAHAYA,Dunia=BAYANG2.
Bile kite kejar cahaya,otomatik bayang2 folo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 08-10-2004, 02:31 PM
Novice Webmaster
 
Join Date: Nov 2003
Location: malaysia
Posts: 25
Rep Power: 0
alien3d is on a distinguished road
Send a message via MSN to alien3d Send a message via Yahoo to alien3d
susah sanget

Guna jek dreamweaver untuk buat code session
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 10-10-2004, 03:18 PM
YajivMalhotra's Avatar
Novice Webmaster
 
Join Date: Oct 2004
Location: Johor Bahru, Malaysia
Posts: 41
Rep Power: 0
YajivMalhotra is on a distinguished road
Send a message via Yahoo to YajivMalhotra
well... session ni senang jer.. kalau faham concept dia.

hmm.. ni code paling simple untuk session..


if (!$_SESSION['username']) {
include("login.php");
}
else {
include("page.php");
}


hmm.. katakan.. lepas seseorang login.. dia akan diforward ke page page.php... kalau non member.. dia akan.. ke page.. login.php..

ni bukan code complex... ni untuk.. strict kan page ke member / non-member..:P

Last edited by YajivMalhotra; 10-10-2004 at 03:21 PM.
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
www.vivientheplay.org/main.htm simmu Websites Review and Suggestion 8 17-05-2005 05:24 PM
php bleh run ngan pws kan? therion Website Programming 34 27-01-2004 05:47 PM
Main Game kat sini duwe Websites Review and Suggestion 2 25-12-2003 01:44 AM
cammane nak berinteract ngan cgi or ngan any file eg. text file nos Website Design 7 12-08-2002 11:30 AM
jom main bola..... donut Mamak Stall 1 24-06-2002 11:24 PM



All times are GMT +8. The time now is 10:40 PM. 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.