-1

Is there any other way to get a computer mac address and able to redirect page i notice that if i remove the code for getting the mac address the redirect / header works

    <?php
    session_start();
    include('dbConnect.php');

    ob_start(); // Turn on output buffering
    system(‘ipconfig /all’); //Execute external program to display output
    $mycom=ob_get_contents(); // Capture the output into a variable
    ob_clean(); // Clean (erase) the output buffer
    $findme = “Physical”;
    $pmac = strpos($mycom, $findme); // Find the position of Physical text
    $mac=substr($mycom,($pmac+36),17); // Get Physical Address

    $qry=("SELECT * FROM table_comp_list WHERE comp_mac = '$mac'");
    $result=mysql_query($qry);  

    if($result)
        {
        if(mysql_num_rows($result) != 1) 
            {
                header("Location: add.php");
                die();
            }
        else
            {
                header("Location: edit.php");
                die();
            }
        }?>
Ozarraga_AB
  • 939
  • 5
  • 15
  • 24
  • 1
    just so you know this is probably the most common question on S.O –  Oct 20 '16 at 05:43
  • Simple, because you output before sending headers –  Oct 20 '16 at 05:45
  • 1
    Possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Rasclatt Oct 20 '16 at 05:46
  • i am new in coding and i got the code to get the mac on S.O also is there other way to get mac address or alternate way to redirect page? – Ozarraga_AB Oct 20 '16 at 05:46
  • If you are using note pad or something to write your script, it's messing up your quotes as in `‘ipconfig /all’`. Should be `'ipconfig /all'`. Those quotes are writer's quotes and used for when you are writing an essay or something. – Rasclatt Oct 20 '16 at 06:02
  • php will not able to find client / user mac address. you code is working on server's mac address (if it works properly) and the redirect issue is not depend on mac address – Shahadat Hossain Khan Oct 20 '16 at 06:36

1 Answers1

-1

Try this at start of your code. Add @ before session_start();

      <?php
@session_start();
// your code goes here -

?>
  • what is reason to Add @ before session_start(); – Archish Oct 20 '16 at 05:53
  • putting an @ before a function call suppresses any errors that may be reported during the course of that function It was worked for me . So , I have shared my knowledge . It is a relevant answer to this question.. No need of downvote.. – Siddeshwar Vanga Oct 20 '16 at 05:58
  • 2
    It is better to figure out why an error is occurring rather then to just try and suppress any possible errors. – Rasclatt Oct 20 '16 at 05:59
  • 1
    yes you have share your knowledge, but solving error is more important than hiding them, and i think your answer don't match question so someone had down vote. – Archish Oct 20 '16 at 06:07
  • Also, you are assuming that `session_start()` is causing the error. Usually that happens if you have another `session_start()` previously set, then you will get a Warning saying session has already started which then disrupts any `header` redirects. The OP has not indicated what the error actually was so you can not really assume it's because of `session_start();` – Rasclatt Oct 20 '16 at 06:09