| | |
session in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 45
Reputation:
Solved Threads: 2
i'm a newbie in php and maybe my question is so silly.
i tried to create a session in a file named login.php
but, $_SESSION['level'] is not recognized in other files like manager.php, gudang.php, and kasir.php
is there something wrong with my code?
thanks for your helps.
i tried to create a session in a file named login.php
PHP Syntax (Toggle Plain Text)
<?php include "koneksi.inc.php"; $name=$_POST['name']; $password=$_POST['password']; $hasil=mysql_query("SELECT * FROM TabelPegawai WHERE nama='$name' AND password='$password'"); $row=mysql_fetch_array($hasil); if ($row[nama]==$name AND $row[password]==$password) { session_start(); $_SESSION['namauser']=$row[nama]; $_SESSION['passuser']=$row[password]; $_SESSION['level']=$row[jabatan]; if($_SESSION['level']=="Manager") {header("location: manager.php");} else if($_SESSION['level']=="Kasir") {header("location:kasir.php");} else if($_SESSION['level']=="Gudang") {header("location:gudang.php");} else {header("location:http://www.google.com");} } else {header("location:http://www.yahoo.com");} ?>
but, $_SESSION['level'] is not recognized in other files like manager.php, gudang.php, and kasir.php
is there something wrong with my code?
thanks for your helps.
Last edited by AirGear; Nov 4th, 2009 at 3:32 pm.
•
•
Join Date: Jul 2009
Posts: 45
Reputation:
Solved Threads: 2
0
#4 Nov 4th, 2009
oh, it works if i start the session in every page that needs session variables. i also must start the session in a php file that destroy the session right? like this :
am i right?
PHP Syntax (Toggle Plain Text)
<?php session_start(); session_destroy(); ?>
am i right?
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
0
#5 Nov 4th, 2009
•
•
•
•
oh, it works if i start the session in every page that needs session variables. i also must start the session in a php file that destroy the session right? like this :
PHP Syntax (Toggle Plain Text)
<?php session_start(); session_destroy(); ?>
am i right?
PHP Syntax (Toggle Plain Text)
if (!isset($_SESSION)) { session_start(); }
Dave
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
0
#7 Nov 4th, 2009
•
•
•
•
You don't need to check. session_start() will not start a new session overwriting the old one. It just propagates.
session_destroy wouldn't be used very often, unless in a logout page or similar. You wouldn't have a session_start in this file as well (I don't think).
D
![]() |
Similar Threads
- How to start new session in php (PHP)
- Session in PHP (PHP)
- please help me in session in php (PHP)
- Need help with session in php..... (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP echo email address as mailto
- Next Thread: redirecting in php
Views: 305 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alexa apache api array beginner binary broadband broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network oop parse paypal pdf php problem query radio random recursion redirect regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable variables video web xml youtube






