PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
lepi
Forum Newbie
Posts: 2 Joined: Mon Mar 17, 2008 11:10 am
Post
by lepi » Mon Mar 17, 2008 11:39 am
i am new in PHP,and ofcourse i have a problem
so,here is my problem
with first php i create session variable,but in sibling php i dont have it in session
here is my code
first.php
Code: Select all
<?header("Content-type: text/html");?>
<? session_start();
$_SESSION["myVariable"] = 1;?>
second.php
Code: Select all
<?header("Content-type: text/html");?>
<?
$myVariable=$_SESSION["myVariable"];
if($myVariable==null) {
?>Session variable doesnt exist<?
}
else {
?>Session variable exist<?
}
scriptah
Forum Commoner
Posts: 27 Joined: Sat Mar 15, 2008 8:58 pm
Location: Long Island, NY
Post
by scriptah » Mon Mar 17, 2008 11:49 am
On second.php you should also call session_start( ) before any output.
lepi
Forum Newbie
Posts: 2 Joined: Mon Mar 17, 2008 11:10 am
Post
by lepi » Mon Mar 17, 2008 11:58 am
thnx
i figured out by my self,but thnx on fast answer
i am java programmer,so i have a little problem with php
but my hosting site has only PHP,so....
Zoxive
Forum Regular
Posts: 974 Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan
Post
by Zoxive » Mon Mar 17, 2008 11:58 am
lepi wrote: first.php
Code: Select all
<?header("Content-type: text/html");?>
<? session_start();
$_SESSION["myVariable"] = 1;?>
->
Code: Select all
<?php
session_start();
//header("Content-type: text/html"); // Not Needed
//
$_SESSION['myVariable'] = 1;
lepi wrote: second.php
Code: Select all
<?header("Content-type: text/html");?>
<?
$myVariable=$_SESSION["myVariable"];
if($myVariable==null) {
?>Session variable doesnt exist<?
}
else {
?>Session variable exist<?
}
->
Code: Select all
<?php
session_start();
//header('Content-type: text/html'); // Not Needed
$myVariable = isset($_SESSION['myVariable'])? $_SESSION['myVariable'] : NULL;
if(!empty($myVariable)):?>
Session variable doesnt exist
<?php elseif: ?>
Session Variable Exists = <?php echo $myVariable; ?>
<?php endif; ?>
Alternate ->
Code: Select all
<?php
session_start();
//header('Content-type: text/html'); // Not Needed
$myVariable = isset($_SESSION['myVariable'])? $_SESSION['myVariable'] : NULL;
if(!empty($myVariable)){
echo 'Session variable doesnt exist';
}else{
echo 'Session variable exists = ' . $myVariable;
}