Strange string behaviour
Posted: Mon Mar 14, 2005 9:26 am
Hi There,
For some reason, the following code:
On the first run of the script with the 'a' parameter in the URL, it runs fine and sets $_SESSION['agents'] to 'a'.
However, on the second run, it sets the $_SESSION variable to 'Array|'.$_GET['a']
In other words, while it adds $_GET['a'] onto the end of $_SESSION['agents'] like I'd expect, the first element gets changed into 'Array'. Not sure why - any ideas?
Many thanks
Mark
feyd | Please use
For some reason, the following code:
Code: Select all
if(isset($_GET['a']))
{
// First make some checks
$agents = explode('|', $_SESSION['agents']);
if(count($agents) == 3)
{
echo '<FONT COLOR="#FF0000">Only a maximum of 3 agents may be referred the client.</FONT>';
}
else
{
// Add to cookie variable
if($_SESSION['agents']=='')
{
$_SESSION['agents'] = $_GET['a'];
}
else
{
$str = array();
$str[] = $_SESSION['agents'];
$str[] = '|'.$_GET['a'];
$_SESSION['agents'] = implode("",$str);
}
}
}
echo '['.$_SESSION['agents'].']';However, on the second run, it sets the $_SESSION variable to 'Array|'.$_GET['a']
In other words, while it adds $_GET['a'] onto the end of $_SESSION['agents'] like I'd expect, the first element gets changed into 'Array'. Not sure why - any ideas?
Many thanks
Mark
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]