Forum Moderators: coopster

Message Too Old, No Replies

Session for connection bandwidth?

Session remembers dialup or broadband during visit?

         

JAB Creations

12:25 am on Jan 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have features on my site that I know I could modify differently for those using broadband and dialup. When people enter my site they choose to enter either by choosing broadband or dialup ... based on this decision is there a way I could create simply just a session that during their visit when they come across a part that I could based on their initial choice have a link specific to their connection speed? Here is my outline...

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.

ergophobe

10:26 pm on Jan 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One simple way, which would require a splash screen is:

<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.

jshpro2

1:35 am on Jan 11, 2005 (gmt 0)

10+ Year Member



Or instead of sesions, you could use cookies so they don't have to pick each time, set the cookies expire time as $time
where
$time = time() + (3600*24*$days);

(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.

JAB Creations

8:08 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool ... though I am still a bit of a php newb so how do I make it print the hyperlink? Here is my newb guess IoI...


{
$_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.

ergophobe

8:14 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well, no, you need to print the entire hyperlink, so you could do something like

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

JAB Creations

8:15 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No wait.... I had the wrong idea... I want to have the links that depend on the variables stored on the pages themselves not on the config file...

JAB Creations

8:37 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for your help!

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;
}
?>

JAB Creations

9:34 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you click on broadband or dialup the session passes the BB value (true/false) but ALWAYS prints broadband whereas it should print dialup. I took care of the parsing error...

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;
}
?>

JAB Creations

9:45 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IT always thinks it's true.

ergophobe

9:59 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you resetting $_SESSION['bb'] based on the $_GET values?

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']);
}

JAB Creations

10:39 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I partially understand the concept of ending the session...

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?

JAB Creations

10:43 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To make it easier to understand the state of things...could you make the script REDIRECT the browser back index.php IF there is no value for BB? I assume you would do this in config.php?

ergophobe

11:07 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




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.

JAB Creations

12:37 am on Jan 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got this code ...


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>