read file problem

Discussion in 'PHP' started by mirosoft1, Feb 5, 2008.

  1. #1
    i have i file on it username and passwoed and i want to use them on the code
    the code read the values but when i use it it is not working
    i want help please and this is the code

    $myFile = "file.txt";
    $fh = fopen($myFile, 'r');
    $cpuser = fgets($fh);
    $cppass = fgets($fh);

    i put eah line on a variable then i use this $cpuser and $cppass but the code not working
     
    mirosoft1, Feb 5, 2008 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    $fh have both user name and password. You have to extract them. In which format you are saving login pass in "file.txt" paste here so we can better understand and help you.
     
    greatlogix, Feb 5, 2008 IP
  3. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    i use this password and username on the control panel of the account that creat an email account
    this is the code



    <?php
    $myFile = "file.txt";
    $fh = fopen($myFile, 'r');
    $cpuser = fgets($fh);
    $cppass = fgets($fh);
    $cpdomain = fgets($fh);

    function getVar($name, $def = '') {
    if (isset($_REQUEST[$name]))
    return $_REQUEST[$name];
    else
    return $def;
    }

    // check if overrides passed
    $username = getVar('username', '');
    $epass = getVar('password', $epass);
    $edomain = getVar('domain', $edomain);
    $equota = getVar('quota', $equota);

    $msg = '';

    if (!empty($username))
    while(true) {

    if ($antispam) {
    @session_start(); // start session if not started yet
    if ($_SESSION['AntiSpamImage'] != $_REQUEST['anti_spam_code']) {
    // set antispam string to something random, in order to avoid reusing it once again
    $_SESSION['AntiSpamImage'] = rand(1,9999999);

    // let user know incorrect code entered
    $msg = '<h2>Incorrect antispam code entered.</h2>';
    break;
    }
    else {
    // set antispam string to something random, in order to avoid reusing it once again
    $_SESSION['AntiSpamImage'] = rand(1,9999999);
    }
    }

    // Create email account
    $f = fopen ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$username&domain=$edomain&password=$epass&quota=$equota", "r");
    if (!$f) {
    $msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';
    break;
    }

    $msg = "<h2>Email account {$username}@{$edomain} created.</h2>";

    // Check result
    while (!feof ($f)) {
    $line = fgets ($f, 1024);
    if (ereg ("already exists", $line, $out)) {
    $msg = "<h2>Email account {$euser}@{$edomain} already exists.</h2>";
    break;
    }
    }
    @fclose($f);

    break;
    fclose($fh);

    }

    ?>
     
    mirosoft1, Feb 5, 2008 IP
  4. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #4
    Can you post sample contents of file "file.txt"?
     
    greatlogix, Feb 5, 2008 IP