Variable always stuck as True???????
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Variable always stuck as True???????
Here is my php script... it's supposed to create a session and be used throughtout my site to remember if the user choose Broadband or Dialup so I can when neccesary have the PHP print the hyperlink that is most suitable for their bandwidth.
The problem is that the variable is always passed as true.
Someone helped me make this code on a different forum and is talking to me like I have any idea of how to do anything besides create a static variable or how to set an includes.
For me to learn from this I have to be able to compare apples to oranges so if you just post a snippet of code I wont progress at all. I think this has to do with index2.php as I put that code together ... so if it is please post the full PHP code for that page and if his cde is bad please post the full PHP code for those file.
INDEX.PHP
__________
<?php include("config.php");
if($_GET['bb'] == false)
{ unset($_SESSION['bb']); } ?>
<html><head></head><body>
<a href="index2.php?bb=true">Broadband</a> ~ <a href="index2.php?bb=false">Dial-Up</a>
</body></html>
CONFIG.PHP
__________
<?
session_start();
if($_GET['bb'] == false)
{
unset($_SESSION['bb']);
}
if (empty($_GET['bb']) && empty($_SESSION['bb']))
{
$_SESSION['bb'] = false;
}
else
{
$_SESSION['bb'] = true;
}
?>
INDEX2.PHP
__________
<html>
<head>
</head>
<body>
<?php include("config.php");
if ($_SESSION['bb'] == true)
{
echo 'Broadband';
}
else {
echo 'Dialup';
}
?>
</body>
</html>
The problem is that the variable is always passed as true.
Someone helped me make this code on a different forum and is talking to me like I have any idea of how to do anything besides create a static variable or how to set an includes.
For me to learn from this I have to be able to compare apples to oranges so if you just post a snippet of code I wont progress at all. I think this has to do with index2.php as I put that code together ... so if it is please post the full PHP code for that page and if his cde is bad please post the full PHP code for those file.
INDEX.PHP
__________
<?php include("config.php");
if($_GET['bb'] == false)
{ unset($_SESSION['bb']); } ?>
<html><head></head><body>
<a href="index2.php?bb=true">Broadband</a> ~ <a href="index2.php?bb=false">Dial-Up</a>
</body></html>
CONFIG.PHP
__________
<?
session_start();
if($_GET['bb'] == false)
{
unset($_SESSION['bb']);
}
if (empty($_GET['bb']) && empty($_SESSION['bb']))
{
$_SESSION['bb'] = false;
}
else
{
$_SESSION['bb'] = true;
}
?>
INDEX2.PHP
__________
<html>
<head>
</head>
<body>
<?php include("config.php");
if ($_SESSION['bb'] == true)
{
echo 'Broadband';
}
else {
echo 'Dialup';
}
?>
</body>
</html>
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Your code here:
You need to check the value passed more like this:
sets $_GET['bb'] to 'true' or 'false'.. which is always true, because they are text.Code: Select all
<a href="index2.php?bb=true">Broadband</a> ~ <a href="index2.php?bb=false">Dial-Up</a>
You need to check the value passed more like this:
Code: Select all
if(!isset($_GETї'bb']) || $_GETї'bb'] == 'false')
unset(.....);
else
$_SESSION....- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
-
Black Unicorn
- Forum Commoner
- Posts: 48
- Joined: Mon Jun 16, 2003 9:19 am
- Location: United Kingdom
Try this:
Code: Select all
INDEX.PHP
__________
<?php include("config.php");
if($_GETї'bb'] == 'false')
{ unset($_SESSIONї'bb']); } ?>
<html><head></head><body>
<a href="index2.php?bb=true">Broadband</a> ~ <a href="index2.php?bb=false">Dial-Up</a>
</body></html>
CONFIG.PHP
__________
<?
session_start();
if($_GETї'bb'] == 'false')
{
unset($_SESSIONї'bb']);
}
if (!isset($_GETї'bb']) && !isset($_SESSIONї'bb']))
{
$_SESSIONї'bb'] = 'false';
}
else
{
$_SESSIONї'bb'] = 'true';
}
?>
INDEX2.PHP
__________
<html>
<head>
</head>
<body>
<?php include("config.php");
if ($_SESSIONї'bb'] == 'true')
{
echo 'Broadband';
}
else {
echo 'Dialup';
}
?>
</body>
</html>- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact: