Jump to content

code not executing?


Ilovetopk

Recommended Posts

When i submit my data via the form to my script script, it shows a blank page.  When i view the source, it shows my php code.

 

when i move the same script to the page with my form, it executes fine.  why would this be?  Is it something with permissions?

<?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 = "[email protected]";
$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); 
?>

Link to comment
https://forums.phpfreaks.com/topic/195750-code-not-executing/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.