| | |
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; 24 Days Ago at 3:32 pm.
•
•
Join Date: Jul 2009
Posts: 45
Reputation:
Solved Threads: 2
0
#4 24 Days Ago
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 24 Days Ago
•
•
•
•
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
0
#6 24 Days Ago
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).
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).
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
0
#7 24 Days Ago
•
•
•
•
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
| Thread Tools | Search this Thread |
apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code cron curl database dataentry date display duplicates dynamic ebooks echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google href htaccess html image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching mediawiki menu mlm multiple mysql number oop paypal pdf php phpincludeissue problem query radio random recursion recursive remote script search server sessions shot sms source sp space speed sql subdomain subscription syntax system table tag tutorial tutorials update upload url validator variable vbulletin video web white youtube





