Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello!

I need some help removing a thing called the BOM[^] in my PHP code. I'm struggling.

All the Q&As I've seen so far seem to say that this thing appears because of the encoding in which code is saved, whereas my BOM seems to appear from nowhere during execution.

Basically, I have a jquery ajax call...

JavaScript
$.ajax({
        type: "POST",
        url: "php/session.php",
        data: { name: a_name, password: a_password, company: a_company, q: "email" }
    })
    .done(function (msg) {
        a_email = msg;
        updatePersonals();
        setTimeout(function () { slide("#Page7") }, waitback);
    });

and the code executed if q=email in session.php is as follows:
PHP
//Just double check the creds. They've already been verified in a previous ajax call, when the company name "BoringWork" was passed to the client.
if (checkUser($name, $password)) {
    $company = $_POST["company"];

    //Have to come back to this.
    //$datafile = '../../accounts/' . $company . '/' . $name . '/' . $CONST_account . '/email.txt';

    $datafile = clean('../../accounts/' . $company . '/' . $name . '/' . $CONST_account . '/');

    //NOTE 1
    if (!file_exists($datafile)) {
        mkdir($datafile, 0777, true);
    }

    $fp = fopen($datafile . 'email2.txt', 'w');
    fwrite($fp, $rank);
    fclose($fp);

    die;

    //This is what I want to run, but it doesn't work because
    //somehow  gets appended to $company.
    if (file_exists($datafile)) {
        $contents = file_get_contents($datafile);
        echo $contents;
    } else {
        echo ':-( Your information is corrupted.';
    }
} else {
    echo 'This_should_not_h@ppen.com';
}


Now if a member was named "Imaginary Dude", and was at a company called "BoringWork", then I expect the code at "NOTE 1" to produce a directory of "../../accounts/Boring Work/Imaginary Dude/".

Unfortunately, I get an folder of "../../accounts/Boring Work/Imaginary Dude/".

I've got the code before the "die;" because I'm trying to pass the user's email to the client, and this code seems to reveal that I was getting errors because somehow this  thing, called a BOM by my research so far, is mucking up my filepath.

So does anyone know what this BOM (aka ) thing is, and why I'm getting it? I'm stuck.
Posted
Updated 16-Dec-13 0:09am
v4

1 solution

I have no real idea how I managed to fix it, but running this code on the company name when the server first passed it back seems to have helped.
JavaScript
function cleanGarbage(input) {
    var output = "";
    var acceptable = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM 1234567890";
    for (var i = 0; i < input.length; ++i) {
        if (acceptable.indexOf(input[i]) != -1)
            output += input[i];
    }
    return output;
}

And all suddenly became well. :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900