Jump to content

php won't execute code!


Recommended Posts

I have wordpress in one directory on my website, and in another I have a test login form and other thing.

 

The php for one page, my recover password script, will not execute. when i click submit and my form sends the data, it shows a blank page, and the source is my php code.

i'm running windows 7 home premium, using firefox to browse the web, i have tested with IE.

 

my script is below:

<?php echo "World!"; ?>
<?php
//enters connection details
require_once('config.php');

//connects to mysql database
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//selects database
$db = mysql_select_db(DB_DATABASE, $link);
if(!$db) {
	die("Unable to select database");
}

//cleans posted login name
$login = $_POST['user'];

//gets email from server
$query="SELECT email FROM members WHERE login='$login'";
$result=mysql_query($query);
if(!$result) {
	print("Query Error: ".mysql_error());
}
$row = mysql_fetch_array($result);

//sets $email as their emqail address	
$email = $row['email'];

//generates random password
class utility {

    static $random = '';

    // generates a random password
    // By default of length 12 having special characters
    static function generate_password($length = 12, $special_chars=true) {
      $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
      if($special_chars) $chars .= '!@#$%^&*_-()';

      $password = '';
      for($i=0; $i<$length; $i++)
        $password .= substr($chars, self::generate_random_number(0, strlen($chars)-1), 1);
      return $password;
    }

    // generates a random number between $min and $max
    static function generate_random_number($min=0, $max=0) {
      // generate seed. TO-DO: Look for a better seed value everytime
      $seed = mt_rand();

      // generate $random
      // special thing about random is that it is 32(md5) + 40(sha1) + 40(sha1) = 112 long
      // hence if we cut the 1st 8 characters everytime, we can get upto 14 random numbers
      // each time the length of $random decreases and when it is less than 8, new 112 long $random is generated
      if(strlen(self::$random) < 8 ) {
        self::$random = md5(uniqid(microtime().mt_rand(), true).$seed);
        self::$random .= sha1(self::$random);
        self::$random .= sha1(self::$random.$seed);
      }

      // take first 8 characters
      $value = substr(self::$random, 0, ;

      // strip first 8 character, leaving remainder for next call
      self::$random = substr(self::$random, ;

      $value = abs(hexdec($value));
      // Reduce the value to be within the min - max range. 4294967295 = 0xffffffff = max random number
      if($max != 0) $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
      return abs(intval($value));
    }

  }


//defines random password as variable
$password = utility::generate_password();

//updates password on database
$query="UPDATE members SET passwd=md5('$password') WHERE login='$login'";
$result=mysql_query($query);
if(!$result) {
	print("Query Error: ".mysql_error());
}

//sends password to email address
$to = "$email";
$subject = "Password recovery";
$message = "Your information on Ilovetopk.is-a-geek.com:
Login: $login
Password: $password
Email: $email
Login in and change your password as soon as possible.
If you did not want to reset your password, please inform me and change it back to normal.
Please do not respond to this email.";
$from = "admin@ilovetopk.is-a-geek.com";
$headers = "From: $from";

$mail=mail($to,$subject,$message,$headers);

//redirects or tells of failure
if($mail) {
	header("location:'recover-success.php'");
	exit();
}
else {
	die("Could not mail password, try again in a few minutes, or contact the admin.");
}

//unset database
unset($db); 
?>

 

the "hello world" was just for testing.

also, my view source goes to notepad ++, and it says the pages name is recover-password.php.htm is this a problem?

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.