0

I have the php below that works vary vary fine on localhost apache server (WAMP server) but when i put it online withowt any reason or error it doesnt do its job ! please need an answer although i will change my hosting server i dont like their services because there are many functions disabled. (update : i have a "html code" that is the profile that this code should logon-to . the profile html is after the php . this php has the problem that shows the die message even when the user and password is correct. this problem only on online server)


<?php

function password($username='noneuser') {

  $tegjitha=file_get_contents("pasetkkadmin.txt");
  $infot=preg_split('/'.PHP_EOL.'/',$tegjitha,-1,PREG_SPLIT_NO_EMPTY);
  $final=null;
  foreach ($infot as $info) {
    $pos=preg_split('/:/',$info,-1,PREG_SPLIT_NO_EMPTY);

    if ($pos[0]==$username){
      $final=$pos[1];
    }

  }
  return $final;


}


function isuser($input) {
  $tegjitha=file_get_contents("pasetkkadmin.txt");
  $infot=preg_split('/'.PHP_EOL.'/',$tegjitha,-1,PREG_SPLIT_NO_EMPTY);
  $rezultati=false;
  foreach ($infot as $info) {
    $pos=preg_split('/:/',$info,-1,PREG_SPLIT_NO_EMPTY);
    if ($input==md5('albipatozi'.$pos[0])) { $rezultati=true;}

  }
  return $rezultati;
}


if  ( isset($_GET['dil'])  ) {
  setcookie('mbajmend','',time()-3600*24*365);
  die('<meta http-equiv="REFRESH" content="0;url=index.php" />');

}

if  ( isset($_POST['username']) && !empty($_POST['username']) ) {
  $username=$_POST['username'];

} else {$username=null;}

if  ( isset($_POST['pass']) && !empty($_POST['pass']) ) {
  $passwd=sha1('justastring£"'.$_POST['pass']);


} else {$passwd='none';}

if  ( isset($_POST['mbajmend']) && !empty($_POST['mbajmend']) ) {
  $koha=time()+3600*24*60;
} else {$koha=null;}

$duhet=password($username);
if ($passwd==$duhet) { 


  setcookie('mbajmend',md5('sdaggs'.$username),$koha);


} elseif (!( isset($_COOKIE['mbajmend']) && isuser($_COOKIE['mbajmend'])  )) {


  setcookie('mbajmend','',time()-3600*24*360);
  if (isset($_SERVER['HTTP_REFERER']) &&     (preg_match('/[index.php]$/',$_SERVER['HTTP_REFERER']) ||     preg_match('/[admin\/]$/',$_SERVER['HTTP_REFERER'])) ) { $textshtes='Perdoruesi ose     Fjalkalimi jane Gabim !  '; }
  else { $textshtes='Ju Lutem Vendosni Te Dhenat Thuaja'; }

die('<body style="background:lightgrey;">
<div id="trupi" style="position:relative; background:#999999; margin:auto; width:360px;     margin-top:160px; height:260px;">
<form id="form1" name="form1" method="post" action="" style="position:absolute;     margin:56px; text-shadow:black; font-style:oblique; color:darkred">
  <label><strong>Perdoruesi:&nbsp;</strong>
  <input type="text" name="username" />
   </label>
  <p>
   <label><strong>Fjalekalimi:</strong>
   <input type="password" name="pass" />
   </label>
  </p>
  <p>
    <label>
    <input type="checkbox" name="checkbox" value="checkbox" />
    Me Mbaj Mend te Ky Kompjuter</label>
  </p>
  <p>
    <label style="float:right;">
    <input type="submit" value="Identifikohu"  />
    </label>
  </p>
  </form><p style="text-align:center; color:darkred; background:grey">    <b>'.$textshtes.'</b></p>
 </div>
 </body>

  ');

 } 

 ?>
<html>
this should be shown when user and passord is correct :)
</html>

i tried to echo every single variable one by one step by step and everything is OK exept the fact it doesnt work

the passdords txt file is pasetkkadmin.txt- its model is

superadmin:a3b22231bbe113a948a349af09cea4e4129584de

the first line is : superadmin and its password is : albi whith that data it should work but it doesnt

4
  • 1
    Sifting through your code is very difficult; do you know about indentation? You can indent blocks of code to make things more readable. Also, do you get any particular error? Have you made any debugging attempts? Commented Apr 5, 2012 at 23:37
  • yes i have made but no error rezultet. (by the way the code on my pc is in blocks but here im not adapted to use the 4 spaces needed for the code so i have messed it up a little when i copy-pasted it ) Commented Apr 5, 2012 at 23:41
  • "doesn[']t do its job"; "doesn[']t work" -- what specifically isn't working? (We shouldn't have to ask!) Commented Apr 5, 2012 at 23:54
  • hahaha after this php code i have an html code that is the profile html . this php shows the die message everytime and i dont get the profile html showd. :D nice anotation by the way Commented Apr 6, 2012 at 0:00

1 Answer 1

2

Local you use WAMP(it's windows), but online the server usually runs on a Linux-system.

The difference is, that PHP_EOL has different values on Windows(CR+LF) and Linux(LF), so your pasetkkadmin.txt will not work like expected with the used PHP-code when you create it on windows and upload it onto a linux-server.

Example pasetkkadmin.txt

foo:bar[CR][LF]
foo2:bar2

On windows, splitted by PHP_EOL([CR][LF]) it will be:

array(0=>foo:bar,
      1=>foo2:bar2)

On linux, splitted by PHP_EOL([LF]) it will be:

array(0=>foo:bar[CR],
      1=>foo2:bar2)
Sign up to request clarification or add additional context in comments.

2 Comments

but the string returned from the code password is identical to the password and the problem with my code stays to this point : $duhet=password($username); if ($passwd==$duhet) { // put the cookie } . even $passwd is identically to $duhet the server doesnt return true the statement ($passwd==$duhet) !! can you explain this ?! because im getting really bored by this code . (so it isnt a OS diference problem)
wehe ! you had right i just tested it and all i had to do was to trim that string in some way and that solved my case. Im vary vary thankful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.