Jump to content

Trouble with missing data when grabbing from a txt file


victorianrider

Recommended Posts

Hey guys,

 

I have a script that grabs data from a separate .txt file which is used to perform certain actions within a user's account. The data I'm having trouble with is user key which is used to authenticate an http header. An example of what the txt file would hold is this:

 

360235276 PbI1c5+PGHSshccYd58AklmTgf5u+tbWZplMRYYxFSivRYw4AZhaVNHwADozYZhZhPnXRSV1rmsrhf1td7w6bJbySZmPHLl+hleyz/Ht4iM=

477947328 cXTnFEVP74RWtAgqM5BlwtgW2i9rP/v44oANzwF+yJZ+9mpvaschyo/HaYP1qUXgIK8nK7jy74iSCEHAgpPgPdryzpReM5cbnVDjRw7h9S0=

503724987 XXEJsklZTFaTx8MLjuNIz0S65Sn02rgbHl2sahdReQdadKP39evIXUoYdr5NyQMWDVE7cRpvn+zJ7mteH7WJzVh0U/sOcSG7kfcuaWpAOfo=

 

The format I have is: account_ID user_key

New account on a fresh line. So in my script I have it grabbing the data as so:

 

$User_DataFile = "accountdata.txt";

$AccData = file($User_DataFile, FILE_SKIP_EMPTY_LINES);


foreach($AccData as $line_num => $line)
{
$AccData = explode(" ", htmlspecialchars(str_replace("    "," ",$line)));

if(stristr($AccData[1], "\n")) $AccData[1] = substr($AccData[1], 0, strlen($AccData[1])-2);

$AccountID = $AccData[0];
$UserKey = $AccData[1];
echo "Account ID: ".$AccountID."<br/>User Key: ".$UserKey."<br/><br/>";

 

I have it set to simply echo out the data for debugging which is where I noticed that any slashes or plus or equal signs were not included.

When run in Apache it returns this:

 

Account ID: 360235276

User Key: PbI1c5+PGHSshccYd58AklmTgf5u+tbWZplMRYYxFSivRYw4AZhaVNHwADozYZhZhPnXRSV1rmsrhf1td7w6bJbySZmPHLl+hleyz/Ht4iM

 

Account ID: 477947328

User Key: cXTnFEVP74RWtAgqM5BlwtgW2i9rP/v44oANzwF+yJZ+9mpvaschyo/HaYP1qUXgIK8nK7jy74iSCEHAgpPgPdryzpReM5cbnVDjRw7h9S0

 

Account ID: 503724987

User Key: XXEJsklZTFaTx8MLjuNIz0S65Sn02rgbHl2sahdReQdadKP39evIXUoYdr5NyQMWDVE7cRpvn+zJ7mteH7WJzVh0U/sOcSG7kfcuaWpAOfo

 

So as you can see by comparison there is no slashes or plus or equal signs present, which is going to be a major problem. Is there any way of getting around this problem?

 

Thanks.

Link to comment
Share on other sites

Hey guys,

 

I have a script that grabs data from a separate .txt file which is used to perform certain actions within a user's account. The data I'm having trouble with is user key which is used to authenticate an http header. An example of what the txt file would hold is this:

 

360235276 PbI1c5+PGHSshccYd58AklmTgf5u+tbWZplMRYYxFSivRYw4AZhaVNHwADozYZhZhPnXRSV1rmsrhf1td7w6bJbySZmPHLl+hleyz/Ht4iM=

477947328 cXTnFEVP74RWtAgqM5BlwtgW2i9rP/v44oANzwF+yJZ+9mpvaschyo/HaYP1qUXgIK8nK7jy74iSCEHAgpPgPdryzpReM5cbnVDjRw7h9S0=

503724987 XXEJsklZTFaTx8MLjuNIz0S65Sn02rgbHl2sahdReQdadKP39evIXUoYdr5NyQMWDVE7cRpvn+zJ7mteH7WJzVh0U/sOcSG7kfcuaWpAOfo=

 

The format I have is: account_ID user_key

New account on a fresh line. So in my script I have it grabbing the data as so:

 

$User_DataFile = "accountdata.txt";

$AccData = file($User_DataFile, FILE_SKIP_EMPTY_LINES);


foreach($AccData as $line_num => $line)
{
$AccData = explode(" ", htmlspecialchars(str_replace("    "," ",$line)));

if(stristr($AccData[1], "\n")) $AccData[1] = substr($AccData[1], 0, strlen($AccData[1])-2);

$AccountID = $AccData[0];
$UserKey = $AccData[1];
echo "Account ID: ".$AccountID."<br/>User Key: ".$UserKey."<br/><br/>";

 

I have it set to simply echo out the data for debugging which is where I noticed that any slashes or plus or equal signs were not included.

When run in Apache it returns this:

 

Account ID: 360235276

User Key: PbI1c5+PGHSshccYd58AklmTgf5u+tbWZplMRYYxFSivRYw4AZhaVNHwADozYZhZhPnXRSV1rmsrhf1td7w6bJbySZmPHLl+hleyz/Ht4iM

 

Account ID: 477947328

User Key: cXTnFEVP74RWtAgqM5BlwtgW2i9rP/v44oANzwF+yJZ+9mpvaschyo/HaYP1qUXgIK8nK7jy74iSCEHAgpPgPdryzpReM5cbnVDjRw7h9S0

 

Account ID: 503724987

User Key: XXEJsklZTFaTx8MLjuNIz0S65Sn02rgbHl2sahdReQdadKP39evIXUoYdr5NyQMWDVE7cRpvn+zJ7mteH7WJzVh0U/sOcSG7kfcuaWpAOfo

 

So as you can see by comparison there is no slashes or plus or equal signs present, which is going to be a major problem. Is there any way of getting around this problem?

 

Thanks.

 

 

Sorry guys, I'm an idiot, I'm not sure what happened last time I ran the script, but now it seems to be working fine -_-

 

So yeah kind of solved :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.