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
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Wed Jul 02, 2014 7:56 am
[text]Undefined index: HTTP_USER_AGENT[/text]
It's warming me about this code. It is simply coming from a browser or computer that doesn't report back what browser "agent" it is??
Is there a way to avoid this error?
Code: Select all
if (($count % 4) == 0)
{
if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='images/divider.png' /></div>";}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'Safari')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='images/divider.png' /></div>";}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==FALSE) {
echo "<div style='clear: both;' /><br/><img src='images/divider_ie.png' /></div>";}
else { echo "<div style='clear: both;' /><br/><img src='images/divider_nogap.png' /></div>";}
}
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Wed Jul 02, 2014 8:38 am
Maybe something like this?
Code: Select all
if (($count % 4) == 0)
{
if (isset($_SERVER['HTTP_USER_AGENT']))
{
if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')!==FALSE)
{
echo "<div style='clear: both;' /><br/><img src='images/divider.png' /></div>";
}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'Safari')!==FALSE)
{
echo "<div style='clear: both;' /><br/><img src='images/divider.png' /></div>";
}
elseif (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==FALSE)
{
echo "<div style='clear: both;' /><br/><img src='images/divider_ie.png' /></div>";
}
else { echo "<div style='clear: both;' /><br/><img src='images/divider_nogap.png' /></div>";}
}
else
{
else { echo "<div style='clear: both;' /><br/><img src='images/divider_nogap.png' /></div>";}
}
}
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Wed Jul 02, 2014 8:48 am
Something like that should work fine, yes.
simonmlewis
DevNet Master
Posts: 4435 Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:
Post
by simonmlewis » Wed Jul 02, 2014 9:56 am
Great thanks. Looking at it again myself, it's blindingly obvious!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.