Forum Moderators: coopster
1.) Broadband or Dial-up?
2.) User chooses dial-up.
3.) User enters bandwidth sensitive area.
4.) Session carries dial-up...passes dialup link instead of broadband.
5.) User only sees the dial-up link...enters correct bandwidth setting based upon step 1.
<p>Enter site: <a href="index.php?bb=true">broadband</a> - <a href="index.php?bb=false">Dial-up</a></p>
index.php
==================
include("config.php");
config.php - included in every page
===================================
session_start();
if (empty($_GET['bb']) && empty($_SESSION['bb']))
{
$_SESSION['bb'] = false;
}
else
{
$_SESSION['bb'] = true;
}
Then on each page you could have a link to switch to BB which would reference the page itself, rather than the site index.
(put days as the amount of days untill they must choose again)
Besides this you could automatically choose for them by testing thier bandwidth and then setting a cookie for like 7 days.
{
$_SESSION['bb'] = false;
print ('index-dial-up.php');
}
else
{
$_SESSION['bb'] = true;
print ('index-bb.php');
}
Thanks to both of you ... I'm interested in sessions but I'm sure someone out there will find this thread and be thankful that you posted the code for cookies.
echo '<a href="http://example.com/page.php">My Page</a>';
or
echo "<a href=\"http://example.com/page.php\">My Page</a>";
or
{
$_SESSION['bb'] = false;
?>
<a href="http://example.com/page.php">My Page</a>
<?php
}
or... well you get the idea
I'm getting this error ...
Parse error: parse error, unexpected '{' inindex2.php on line 13
Here is what I have...
index.php
<html><head></head><body>
<a href="index2.php?bb=true">Broadband</a> ~ <a href="index2.php?bb=true">Dial-Up</a>
</body></html>
index2.php
<html>
<head>
</head><body>
<?php include("config.php");
if ($_SESSION['bb'] = false)
{
echo '<a href="index3bb.php">Broadband</a>';
}
else ($_SESSION['bb'] = true)
{
echo '<a href="index3du.php">Dialup</a>';
}?>
</body>
</html>
config.php
<?
session_start();if (empty($_GET['bb']) && empty($_SESSION['bb']))
{
$_SESSION['bb'] = false;
}
else
{
$_SESSION['bb'] = true;
}
?>
Here are the files...
index.php
<?php include("config.php");
?>
<html><head></head><body>
<a href="index2.php?bb=true">Broadband</a> ~ <a href="index2.php?bb=false">Dial-Up</a>
</body></html>
index2.php
<html>
<head>
</head><body>
<?php include("config.php");
if ($_SESSION['bb'] == true) {
echo 'Broadband';
} else {
echo 'Dialup';
}?>
</body>
</html>
config.php
<?
session_start();if (empty($_GET['bb']) && empty($_SESSION['bb']))
{
$_SESSION['bb'] = false;
}
else
{
$_SESSION['bb'] = true;
}
?>
Somewhere in your script, you'll need to have a means of unsetting the session var once it's set. I'm guessing that you are setting the session var to true and leaving it that way. One easy way to check is to delete the session cookie or
if($_GET['bb'] == false)
{
unset($_SESSION['bb']);
}
I don't know what to do with that snippet of code?
You have to point to a file and say put it between this and this in order for me to look back and understand what you're saying in the original post.
I don't understand the concept of having the config file at all actually... is it saying if there is no variable...and then = true AND false?
I partially understand the concept of ending the session...
The whole idea of a session is that it is persistent. Sometimes this can make things difficult when debugging and you don't expect it to be persistent. As long as the cookie is on your machine with a session id, or the id is in the url, and the session is still valid on the server end, your session data is there. So depending on how long sessions are set up to last on your machine, you might come back tomorrow and $_SESSION['bb'] will still be true. Therefore, you need a means to unset the session if you sometimes want to switch it to false.
I don't know what to do with that snippet of code?You have to point to a file and say put it between this and this in order for me to look back and understand what you're saying in the original post.
It could go anywhere in the program flow, as long as it comes before your test for content switching. In other words, if someone clicks on a link "dial up" which sets the $_GET parameter 'bb' to 'false' as in
<a href="page.php?bb=false">Dial Up</a>
You need to check for that and, if necessary, unset $_SESSION['bb'] or set it to false before you do your check
if (empty($_GET['bb']) && empty($_SESSION['bb']))
otherwise this will evaluate to true. So the last snippet I gave you could go between the
session_start();
and the
if (empty($_GET['bb']) && empty($_SESSION['bb']))
I don't understand the concept of having the config file at all actually...
You don't need it, but it will save you a lot of headache. I always have some config file that handles stuff that must be on every page. That way, if I change session or login implementation, I change one file, which is by default included in every page. No matter how many pages use sessions, I typically only have one place where sessions are started, logins checked and so forth.
if($_GET['bb'] == false)
{
unset($_SESSION['bb']);
}
Both inside the VERY first PHP syntex on the index.php and inside the config.php files and its STILL not working.
I want you to know I really appreciate you helping me but you have to understand I have a devastatingly low concept of how PHP works. I need a solid static example of what I should use...not development concepts that I should apply because concepts are derived from examples that we can relate to.
If the variable is always being passed as true and there is nothing wrong with your code then it has to be the index2.php file that I made an honest effort at trying to figure out.
Here is my index2.php file...what is wrong with it that is making it always pass the variable as true? And please just post the full code so I can copy and paste and then compare between two notepads....thats how I am able to learn.
<html>
<head>
</head><body>
<?php include("config.php");
if ($_SESSION['bb'] == true)
{
echo 'Broadband';
}else {
echo 'Dialup';
}?>
</body>
</html>