7 Replies - 1551 Views - Last Post: 13 March 2013 - 05:34 PM Rate Topic: -----

#1 hugoriffic  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 185
  • Joined: 16-September 09

Page Not Displaying and No Error Messages

Posted 13 March 2013 - 10:37 AM

I have entirely rewritten my code for a log in page. Yet, when I try and test the page online there is nothing there (white page). I'm getting no error messages or other indications as to what might be going wrong. And within my code there are no error messages. I've been staring at the code too long I might be missing the obvious.


Here is the code I am using:

Actual Log In Page:
<?php

require_once('validateLogInForm.php');
$crypt = new encryption_class;
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   $username = &$_POST['username'];
   $password = &$_POST['password'];
   $pswdlen  = (int)$_POST['pswdlen'];
   $adj      = &$_POST['adj'];
   $crypt->setAdjustment($adj);
   $mod      = &$_POST['mod'];
   $crypt->setModulus($mod);
} else {
   $username  = NULL;
   $password = NULL;
   $pswdlen  = 16;
} 

$adj = $crypt->getAdjustment();
$mod = $crypt->getModulus();
$errors = array();
	

	
	//database login
	$dsn = 'mysql:host=XXX;dbname=XXX';
	$username='XXX';
	$password='XXX';
	//variable for errors
	$options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
	//try to run code
	try {
	//object to open database
	$db = new PDO($dsn,$username,$password, $options);
	//check username against password
		$SQL = $db->prepare("Select USER_PASSWORD FROM user WHERE user_name = :UserName");
		$SQL->bindValue(':UserName', $username);
		$SQL->execute();
		$username = $SQL->fetch();
		
        if($username === false)
			{
				$password = null;
		    }
		else
		    {
				$password = $username['USER_PASSWORD'];
				include index.php;
			}
			
		return $password;
		$SQL->closeCursor();
		$db = null;
				
		} catch(PDOException $e){
			$error_message = $e->getMessage();
			echo("<p>Database Error: $error_message</p>");
			exit();
		}

	function showForm($formMessage){
		echo $formMessage;
	}
?>
	



Validate Page
<?php

require_once('logIn.php');

class encryption_class {

    var $scramble1;     // 1st string of characters
    var $scramble2;     // 2nd string of characters

    var $errors;        // array of error messages
    var $adj;           // 1st adjustment value 
    var $mod;           // 2nd adjustment value 

   //create encryption class 
    function encryption_class ()
    {
        $this->errors = array();

        //this scrambles user input
        $this->scramble1 = '! #$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~';
        $this->scramble2 = 'f^jAE]okIOzU[2&q1{3`h5w_794p@6s8?BgP>dFV=m D<TcS%Ze|r:lGK/uCy.Jx)HiQ!#$~(;Lt-R}Ma,NvW+Ynb*0X';

        if (strlen($this->scramble1) <> strlen($this->scramble2)) {
            trigger_error('** SCRAMBLE1 is not same length as SCRAMBLE2 **', E_USER_ERROR);
        } 

        $this->adj = 1.75;  // this value is added to the rolling fudgefactors
        $this->mod = 3;     // if divisible by this the adjustment is made negative

    } 
	
	
    function decrypt ($password, $source)
    // decrypt string into its original form
    {
        $this->errors = array();

        // convert $password into a sequence of numbers
        $fudgefactor = $this->_convertPassword($password);
        if ($this->errors) return;
		//if no user input show error message
        if (empty($source)) {
            $this->errors[] = 'Please Enter A Valid User Name and Password';
            return;
        } 

        $target = null;
        $factor2 = 0;

        for ($i = 0; $i < strlen($source); $i++) {
            // extract a (multibyte) character from $source
            if (function_exists('mb_substr')) {
                $char2 = mb_substr($source, $i, 1);
            } else {
                $char2 = substr($source, $i, 1);
            } 

            // identify its position in $scramble2
            $num2 = strpos($this->scramble2, $char2);
            if ($num2 === false) {
                $this->errors[] = "Source string contains an invalid character ($char2)";
                return;
            } 

            // get a value using $fudgefactor
            $adj     = $this->_applyFudgeFactor($fudgefactor);

            $factor1 = $factor2 + $adj;                 // $factor1 value
            $num1    = $num2 - round($factor1);         // generate $scramble1
            $num1    = $this->_checkRange($num1);       // check range value
            $factor2 = $factor1 + $num2;                // $factor2 value

            // get character from $scramble1
            if (function_exists('mb_substr')) {
                $char1 = mb_substr($this->scramble1, $num1, 1);
            } else {
                $char1 = substr($this->scramble1, $num1, 1);
            } 

            // add to $target string
            $target .= $char1;

        } 

        return rtrim($target);

    } 


    function encrypt ($password, $source, $sourcelen = 0)
    // encrypt string into big mess
    {
        $this->errors = array();

        // convert $password into a sequence of numbers
        $fudgefactor = $this->_convertPassword($password);
        if ($this->errors) return;

        if (empty($source)) {
            $this->errors[] = 'Please Enter A Valid User Name and Password';
            return;
        } 

        // pad $source with spaces 
        $source = str_pad($source, $sourcelen);

        $target = null;
        $factor2 = 0;

        for ($i = 0; $i < strlen($source); $i++) {
            // extract a character from $source
            if (function_exists('mb_substr')) {
                $char1 = mb_substr($source, $i, 1);
            } else {
                $char1 = substr($source, $i, 1);
            } 

            // identify its position in $scramble1
            $num1 = strpos($this->scramble1, $char1);
            if ($num1 === false) {
                $this->errors[] = "Source string contains an invalid character ($char1)";
                return;
            } 

            // get value using $fudgefactor
            $adj     = $this->_applyFudgeFactor($fudgefactor);

            $factor1 = $factor2 + $adj;             // $factor1 value
            $num2    = round($factor1) + $num1;     // generate $scramble2
            $num2    = $this->_checkRange($num2);   // check range value
            $factor2 = $factor1 + $num2;            // $factor2 value

            // extract character from $scramble2
            if (function_exists('mb_substr')) {
                $char2 = mb_substr($this->scramble2, $num2, 1);
            } else {
                $char2 = substr($this->scramble2, $num2, 1);
            }

            // add to $target string
            $target .= $char2;

            

        } 

        return $target;

    } 

    function getAdjustment ()
    // return the adjustment value
    {
        return $this->adj;

    } 
    
    function getModulus ()
    // return the modulus value
    {
        return $this->mod;

    } 
	
    function setAdjustment ($adj)
    // set the adjustment value
    {
        $this->adj = (float)$adj;

    } 
	
    function setModulus ($mod)
    // set the modulus value
    {
        $this->mod = (int)abs($mod);    // must be a positive whole number

    } 
	
	
	
    function _applyFudgeFactor (&$fudgefactor)
    // return value based on the contents of $fudgefactor
    {
        $fudge = array_shift($fudgefactor);     // get 1st number from array
        $fudge = $fudge + $this->adj;           // add in new value
        $fudgefactor[] = $fudge;                // add it to the end of array

        if (!empty($this->mod)) {               //was a mod entered?
            if ($fudge % $this->mod == 0) {     // is it divisible by modifier
                $fudge = $fudge * -1;           // if so then make it negative
            } 
        } 
		
        return $fudge;

    } 
	
	
    function _checkRange ($num)
    // check that $num is valid
    {
        $num = round($num);         // round up to nearest whole number

        $limit = strlen($this->scramble1);

        while ($num >= $limit) {
            $num = $num - $limit;   // value too high, so reduce it
        } // while
        while ($num < 0) {
            $num = $num + $limit;   // value too low, so increase it
        } // while

        return $num;

    }

    
    function _convertPassword ($password)
    // convert $password into numbers
    {
        if (empty($password)) {
            $this->errors[] = 'Please Enter A Valid User Name and Password';
            return;
        } 
		
        $array[] = strlen($password);    // first entry in array is length of $password

        $tot = 0;
        for ($i = 0; $i < strlen($password); $i++) {
            // get a character from $password
            if (function_exists('mb_substr')) {
                $char = mb_substr($password, $i, 1);
            } else {
                $char = substr($password, $i, 1);
            } 
			
            // find its position in $scramble1
            $num = strpos($this->scramble1, $char);
            if ($num === false) {
                $this->errors[] = "Key contains an invalid character ($char)";
                return;
            } 

            $array[] = $num;        // store this in array
            $tot = $tot + $num;     // accumulate total 
        } 

        $array[] = $tot;            // insert total 

        return $array;

    } 


} 
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Page Not Displaying and No Error Messages

#2 Slice  Icon User is offline

  • sudo pacman -S moneyz


Reputation: 245
  • View blog
  • Posts: 719
  • Joined: 24-November 08

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 10:59 AM

Looks like you're missing a closing parenthesis (}) for your try block on your log in page.

Edit: Oh no you're not, my bad. Only skimmed it and missed the catch. But a blank page is usually something left open like a line without a ; or missing a }

This post has been edited by Slice: 13 March 2013 - 11:01 AM

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,549
  • Joined: 23-August 08

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 11:16 AM

http://stackoverflow...-error-messages
Was This Post Helpful? 0
  • +
  • -

#4 hugoriffic  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 185
  • Joined: 16-September 09

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 11:18 AM

View PostJackOfAllTrades, on 13 March 2013 - 07:16 PM, said:


Yeah, I included those and still no errors showed up. I removed them before posting my code here.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3624
  • View blog
  • Posts: 12,527
  • Joined: 12-December 12

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 11:42 AM

What are you expecting it to display? I can't see that you produce any output. You have defined a function showForm() but you don't call this function.

If you are expecting it to display your home page content then you need to modify this:

include index.php;
// to this:
include 'index.php';

assuming that this page is at the same location as the current page. You haven't required the page, so if it is not found it will display nothing; it will create a warning so make sure you have the setting to show all warnings.

This post has been edited by andrewsw: 13 March 2013 - 11:44 AM

Was This Post Helpful? 0
  • +
  • -

#6 hugoriffic  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 185
  • Joined: 16-September 09

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 12:39 PM

I changed three things:

1) I eliminated the "require_once('validateLogInForm.php');" line from the logIn page. I don't believe that this was necessary.
2) I entered showForm(); and exit(); to the opening else statement at the top of the page, and
3) I changed my include statement as andrewsw explained.

Problem is my submit button is calling the validateLogInForm.js and not the validateLogInForm.php page. So, essentially I was doing nothing.

This post has been edited by hugoriffic: 13 March 2013 - 12:40 PM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,549
  • Joined: 23-August 08

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 01:51 PM

WTF are you doing here? Is this a school assignment? If not, STOP TRYING TO INVENT YOUR OWN ENCRYPTION MECHANISM!!! Use something tried and true, like phpass. Going this route as a means of "securing" your data is folly.
Was This Post Helpful? 0
  • +
  • -

#8 hugoriffic  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 185
  • Joined: 16-September 09

Re: Page Not Displaying and No Error Messages

Posted 13 March 2013 - 05:34 PM

View PostJackOfAllTrades, on 13 March 2013 - 09:51 PM, said:

WTF are you doing here? Is this a school assignment? If not, STOP TRYING TO INVENT YOUR OWN ENCRYPTION MECHANISM!!! Use something tried and true, like phpass. Going this route as a means of "securing" your data is folly.
It is for an assignment. I'm still learning PHP so I am writing code as a way to teach myself more advanced techniques. Everyone tells me the best way to learn to code is to write code. So, that is what I have been trying to do lately. Obviously I have no idea as to what I am doing. I think I've made that obvious with my last 20 or so posts.

But there aren't a lot of beginner tutorials out there for PHP (or Javascript, SQL,or any other languages). Most of them are advanced. Or the other tutorials don't teach you how to do anything that you'd ever use in the real world, they just write examples of how to structure the code. So, it's hard. I'm just trying to learn.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1