Login Script Broke on new server, PRETTY please - FREE BEER

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try switching out all this:

Code: Select all

$fp = fopen( $filename, 'r' );
    $file_contents = fread( $fp, filesize( $filename ) );
    fclose( $fp );

    // Place the individual lines from the file contents into an array.

    $lines = explode ( "\n", $file_contents );
with

Code: Select all

$lines = file($filename);
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

trying on yet a different server

Getting error

Notice: Undefined offset: 6 in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 26

Notice: Undefined offset: 5 in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 26

Notice: Undefined offset: 4 in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 26

Notice: Undefined offset: 3 in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 26

Notice: Undefined offset: 2 in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 26

Notice: Undefined offset: 1 in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/BLAH/httpdocs/vpcpages/login.php:26) in /home/httpd/vhosts/BLAH/httpdocs/vpcpages/login.php on line 58



So all i nee dto do is that those offsets and define them 1 by 1? or is there a way to shut defining off?
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

that switch gave me the same erro different line numbers


Th eline giving the UNDEFINED ERRORS IS

list( $memberid, $membername, $contactname, $username, $password, $email, $reportname ) = explode( '|', $line );
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the first row of the file may be blank.. it definitely didn't explode as there weren't any pipes in the string..
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

ok, so I moved it to yet another server and it works to a point, it always fails the first AUTHENTICATION...

any ideas?
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

forgot the code
Last edited by romeo on Sun Aug 01, 2004 5:31 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How's this do?

Code: Select all

<?php

ini_set('display_errors', '1');
ini_set('error_reporting', E_ALL);


$auth = false; // Assume user is not authenticated

if (isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] )) {

    // Read the entire file into the variable $file_contents

    $filename = '../data/webusers.txt';
    $lines = file( $filename );

    // Split each of the lines into a username and a password pair
    // and attempt to match them to $PHP_AUTH_USER and $PHP_AUTH_PW.

foreach ( $lines as $k => $line )
{

$line = trim($line);
if(empty($line)) continue;
if(($num = preg_match_all('#\|#',$line)) != 6)
echo 'line ' . ($k+1) . 'has too ' . ($num < 6 ? 'few' : 'many') . ' pipes:' . "\n" . var_export($line) . "\n" . $line . "\n";

list( $memberid, $membername, $contactname, $username, $password, $email, $reportname ) = preg_split( '#\s*\|\s*#', $line );

if (($username == $_SERVER['PHP_AUTH_USER']) && ($password == $_SERVER['PHP_AUTH_PW']))
      {
            // A match is found, meaning the user is authenticated.
            // Stop the search.
            $auth = true;
            break;
        }
    }
}

if (!$auth) {
    header( 'WWW-Authenticate: Basic realm="Private"' );
    header( 'HTTP/1.0 401 Unauthorized' );
    echo 'Authorization Required.';
    exit;
} else {

$memberid = base64_encode($memberid);
$membername = base64_encode($membername);
$email = base64_encode($email);
$contact = base64_encode($contactname);
$reportname = base64_encode($reportname);

header("Location: http://www.localsupport.com/vpcpages/me ... reportname");
}

?>
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

i got this error Feyd...

Warning: Wrong parameter count for preg_match_all() in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 24
'12 | B.W. Stetson & Company | MR JAMES CRILLEY | james | james123 | floyd@bwstetson.com | mc12snohitat.PDF'line 1has too few pipes: 12 | B.W. Stetson & Company | MR JAMES CRILLEY | james | james123 | floyd@bwstetson.com | mc12snohitat.PDF
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php:24) in /home/httpd/vhosts/localsupport.com/httpdocs/vpcpages/login.php on line 52

By the By... you got a paypal account.. sooner or later your getinga beer ;)
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

a Note

this takes data from a form, then if fails launches the server htaccess box

u can see the site here
http://www.localsupport.com/vpcpages
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

heh, oops :oops: forgot the $matches bit.. :D

Code: Select all

if(($num = preg_match_all('#\|#',$line,$matches)) != 6)
echo 'line ' . ($k+1) . ' has too ' . ($num < 6 ? 'few' : 'many') . ' pipes:' . "\n" . var_export($line,true) . "\n" . $line . "\n";

P.S. I don't drink beer
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

so pepsi ? :)


Still not authenticating on from teh form, only the htaccess

STILL DOESNT WORK ON THE WINDOWS SERVER... GAH I HATE WINDOWS
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

i must have totally forgotten about a PAGE form login as I think its structured poorly for it
Post Reply