Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 724421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:13:14+00:00 2026-05-14T06:13:14+00:00

I am working on an example from a php book and am getting an

  • 0

I am working on an example from a php book and am getting an error on line 8 with this code

<?php

$agent = getenv("HTTP_USER_AGENT");
if (preg_match("/MSIE/i", "$agent"));
{
    $result = "You are using Microsoft Internet Explorer";
}
else if (preg_match("/Mozilla/i", "$agent")); 
{
    $result = "You are using Mozilla firefox";
}
else {$result = "you are using $agent"; }

echo $result;


?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:13:15+00:00Added an answer on May 14, 2026 at 6:13 am

    Try:

    $agent = getenv("HTTP_USER_AGENT");
    if (preg_match("/MSIE/i", $agent)) {
      $result = "You are using Microsoft Internet Explorer";
    } else if (preg_match("/Mozilla/i", $agent)) {
      $result = "You are using Mozilla firefox";
    } else {
      $result = "you are using $agent";
    }
    
    echo $result;
    

    Two things:

    1. You had a semi-colon at the end of your if clauses. That means the subsequent opening brace was a local block that is always executed. That caused a problem because later you had an else statement that wasn’t attached to an if statement; and

    2. Doing "$agent" is unnecessary and not recommended. Simply pass in $agent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a working example code from php doc for using list() with each()
I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
I am working on getting parameter from a function string. For example, my function
I'm working with generating .pdf's from PHP using this library: http://www.fpdf.org/ I am currently
I made a simple plugin from this example : <?php /* Plugin Name: Redirect
I am working through the example from https://blogs.oracle.com/arungupta/entry/java_ee_6_and_nosql . Here is a link to
I got the chat example working from Atmosphere, and now I want to get
My email code isn't working. <?php if(isset($_POST['send'])){ $to = info@erbimages.com ; // change all
I'm running the example from chapter 1 in Head First's PHP and MySQL. I
I'm using wikitools package to parse the wikipedia. I just copy this example from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.