Jump to content

EricOnAdventure

Members
  • Posts

    80
  • Joined

  • Last visited

Posts posted by EricOnAdventure

  1. Oh, and this code too may be relevant....

    <?php
    /*** *** *** *** *** ***
    * @package Quadodo Login Script
    * @file    qls.class.php
    * @start   July 18th, 2007
    * @author  Douglas Rennehan
    * @license http://www.opensource.org/licenses/gpl-license.php
    * @version 1.1.3
    * @link    http://www.quadodo.net
    *** *** *** *** *** ***
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    *** *** *** *** *** ***
    * Comments are always before the code they are commenting.
    *** *** *** *** *** ***/
    if (!defined('QUADODO_IN_SYSTEM')) {
    exit;	
    }
    
    /**
     * Contains everything needed to run the system
     */
    class qls {
    
    	/**
    	 * Construct main class and grab all other classes
    	 * @param string $current_language - The current language
    	 * @return void, but will output error if found
    	 */
    	function qls($current_language) {
            // Get current language constants
            require_once($current_language . '.lang.php');
    
            require_once('Security.class.php');
            $this->Security = new Security($this);
    
            require_once('SQL.class.php');
            $this->SQL = new SQL($this);
    
            // Get configuration information and assign to $config
            $result = $this->SQL->query("SELECT * FROM `{$this->config['sql_prefix']}config`");
    
    		while ($row = $this->SQL->fetch_array($result)) {
    		    $this->config[$row['name']] = $row['value'];
    		}
    
            $this->Security->remove_old_tries();
    
            require_once('User.class.php');
            $this->User = new User($this);
    
            require_once('Session.class.php');
            $this->Session = new Session($this);
    
            require_once('Admin.class.php');
            $this->Admin = new Admin($this);
    
            require_once('Group.class.php');
            $this->Group = new Group($this);
    
            require_once('Upload.class.php');
            $this->Upload = new Upload($this);
    
            $this->main_directory = str_replace('/includes', '', dirname(__FILE__));
    
            // Make sure their account isn't outdated
            $this->User->check_activated_accounts();
    
            // See if someone is logged in 0_0
            $this->User->validate_login();
    
            // Clear any old sessions used by the system
            $this->Session->clear_old_sessions();
    
            // Set the users last action
            if ($this->user_info['username'] != '') {
                $this->SQL->update('users',
                    array('last_action' => time()),
                    array('id' =>
                        array(
                            '=',
                            $this->user_info['id']
                        )
                    )
                );
    	    }
    
    		if ($this->user_info['blocked'] == 'yes') {
    		    die(BLOCKED_ERROR);
    		}
    	}
    
    	/**
    	 * Reference to the function inside User.class.php
    	 * @param string $username - The username
    	 * @return the ID of the username in the form of an integer
    	 */
    	function username_to_id($username) {
    	    return $this->User->username_to_id($username);
    	}
    
    	/**
    	 * Reference to the function inside User.class.php
    	 * @param integer $user_id - The user ID
    	 * @return the username (string)
    	 */
    	function id_to_username($user_id) {
    	    return $this->User->id_to_username($user_id);
    	}
    
    	/**
    	 * Translates a page name into a ID from the database
    	 * @param string $page_name - The name of the page
    	 * @return int
    	 */
    	function page_name_to_id($page_name) {
            $page_name = $this->Security->make_safe($page_name);
            $result = $this->SQL->select('id',
                'pages',
                array('name' =>
                    array(
                        '=',
                        $page_name
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['id'];
    	}
    
    	/**
    	 * Translates a page ID into a name from the database
    	 * @param integer $page_id - The ID of the page
    	 * @return String
    	 */
    	function page_id_to_name($page_id) {
            $page_id = $this->Security->make_safe($page_id);
            $result = $this->SQL->select('name',
                'pages',
                array('id' =>
                    array(
                        '=',
                        $page_id
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['name'];
    	}
    
    	/**
    	 * Translates a group name into an ID from the database
    	 * @param string $group_name - The group name
    	 * @return int
    	 */
    	function group_name_to_id($group_name) {
            $group_name = $this->Security->make_safe($group_name);
            $result = $this->SQL->select('id',
                'groups',
                array('name' =>
                    array(
                        '=',
                        $group_name
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['id'];
    	}
    
    	/**
    	 * Translate a group ID into a name from the database
    	 * @param integer $group_id - The group ID
    	 * @return String
    	 */
    	function group_id_to_name($group_id) {
            $group_id = $this->Security->make_safe($group_id);
            $result = $this->SQL->select('name',
                'groups',
                array('id' =>
                    array(
                        '=',
                        $group_id
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['name'];
    	}
    
    	/**
    	 * Translates a mask name to an ID from the database
    	 * @param string $mask_name - The mask name
    	 * @return int
    	 */
    	function mask_name_to_id($mask_name) {
            $mask_name = $this->Security->make_safe($mask_name);
            $result = $this->SQL->select('id',
                'masks',
                array('name' =>
                    array(
                        '=',
                        $mask_name
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['id'];
    	}
    
    	/**
    	 * Translates a mask ID to a name from the database
    	 * @param integer $mask_id - The mask ID
    	 * @return string
    	 */
    	function mask_id_to_name($mask_id) {
            $mask_id = $this->Security->make_safe($mask_id);
            $result = $this->SQL->select('name',
                'masks',
                array('id' =>
                    array(
                        '=',
                        $mask_id
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['name'];
    	}
    
    	/**
    	 * Opens a file and reads from it
    	 * @param string $file_name - The name of the file
    	 * @return string
    	 */
    	function fetch_file_data($file_name) {
            $file_location = $this->main_directory . '/' . $file_name;
    
            // If it has a 0 file size it won't be readable
            $file_size = filesize($file_location);
            if ($file_size == 0) {
                return '';
            }
            else {
                if (!$file_handle = fopen($file_location, 'r')) {
                    $this->file_data_error = FILE_NOT_OPENABLE;
                    return false;
                }
                else {
                    if (!$file_data = fread($file_handle, filesize($file_location))) {
                        $this->file_data_error = FILE_NOT_READABLE;
                        return false;
                    }
                    else {
                        fclose($file_handle);
                        return $file_data;
                    }
                }
            }
    	}
    
    	/**
    	 * Retrieves the current page hits
    	 * @param string $page_name - The page name
    	 * @return int
    	 */
    	function hits($page_name) {
            $page_name = $this->Security->make_safe($page_name);
            $result = $this->SQL->select('*',
                'pages',
                array('name' =>
                    array(
                        '=',
                        $page_name
                    )
                )
            );
            $row = $this->SQL->fetch_array($result);
            return $row['hits'];
    	}
    
    	/**
    	 * This will generate the activation link using the cookie information
    	 * @param string $generated_code - The code they need
    	 * @param string $username       - The user's username
    	 * @return string
    	 */
    	function generate_activation_link($generated_code, $username) {
    		// See if the domain is prepended with a dot
    		if (substr($this->config['cookie_domain'], 0, 1) == '.') {
    			// Does it have a / at the end?
    			if (substr($this->config['cookie_path'], -1) == '/') {
    			    $activation_link = "http://www{$this->config['cookie_domain']}{$this->config['cookie_path']}activate.php?code={$generated_code}&username={$username}";
    			}
    			else {
    			    $activation_link = "http://www{$this->config['cookie_domain']}{$this->config['cookie_path']}/activate.php?code={$generated_code}&username={$username}";
    			}
    		}
    		else {
    			// Does it have a / at the end?
    			if (substr($this->config['cookie_path'], -1) == '/') {
    			    $activation_link = "http://{$this->config['cookie_domain']}{$this->config['cookie_path']}activate.php?code={$generated_code}&username={$username}";
    			}
    			else {
    			    $activation_link = "http://{$this->config['cookie_domain']}{$this->config['cookie_path']}/activate.php?code={$generated_code}&username={$username}";
    			}
    		}
    
    	    return $activation_link;
    	}
    
    	/**
    	 * Redirects a user to another page
    	 * @param string $url - The new URL to go to
    	 * @return void
    	 */
    	function redirect($url) {
    		switch ($this->config['redirect_type']) {
    			default:
                    header('Location: ' . $url);
                    exit;
    			break;
    			case 2:
    			    echo <<<META
    <html><head><meta http-equiv="Refresh" content="0;URL={$url}" /></head><body></body></html>
    META;
    			    break;
    			case 3:
    			    echo <<<SCRIPT
    <html><body><script>location="{$url}";</script></body></html>
    SCRIPT;
    			    break;
    		}
    	}
    
    	/**
    	 * Grabs all the users that are currently surfing and their info
    	 * @return array
    	 */
    	function online_users() {
            // $five_minutes_ago can be changed if you want it farther back
            $five_minutes_ago = time() - 300;
            $result = $this->SQL->select('*',
                'users',
                array('last_action' =>
                    array(
                        '>',
                        $five_minutes_ago
                    )
                )
            );
    
            $users = array();
    
    		while ($row = $this->SQL->fetch_assoc($result)) {
    		    $users[] = $row;
    		}
    
    	    return $users;
    	}
    	
    	/**
    	 * Outputs the current online users
    	 * @return void
    	 */
    	function output_online_users() {
    	    $users = $this->online_users();
    
    		if (count($users) == 0) {
    		    echo ' ---- ';
    		}
    		else {
    		    $count = 0;
                $string = '';
    
    			foreach ($users as $information) {
                    $prepared_output = str_ireplace('{username}', $information['username'], stripslashes($this->config['online_users_format']));
                    $prepared_output = str_ireplace('{id}', $information['id'], $prepared_output);
    
    				if ($count == 0) {
    				    $string = $prepared_output;
    				}
    				else {
    				    $string .= stripslashes($this->config['online_users_separator']) . $prepared_output;
    				}
    
    			    $count++;
    			}
    
    		    echo $string;
    		}
    	}
    }
    
  2. Hello all, I have a very complex problem, one far beyond me (I tried and got nowhere). I am using the login script from http://www.quadodo.net , and it works quite well. But I ran into an issue the other day, I created a code to pull from my databases. the code worked in a vacuum but when pared up with pages that also used the login script it failed. I'm not sure why, but perhaps a security feature. Anyway, this got me thinking, if this very vital login script is creating a conflict, why try to work around it or fight it, I could just take the code that it already has, code that already pulls from databases and rework it to my desire.  I tried this and uhh,,,wow it was quite beyond me.

    SO in the login script this

     

    $anyvar= $qls->user_info['anycolumn'];

     

    works great, it allows me to pull any column from my login database which I have been adding and adding too. Of course I don't want to add too much to, so I need to rework this script so that I can pull from other databases, the problem is my limited knowledge of PHP and is preventing me from editing the code in a meaningful and effective way. Below is the code whole page that would allow me to use the little code I just showed you. A good porting of this code is for security, and it does make sense to keep that :D  Any advice on how I could start? Or perhaps you need more information? Really this is so far beyond me that I am so lost that I can't even find myself.

    <?php
    if (!defined('QUADODO_IN_SYSTEM')) {
        exit;
    }
    
    /**
     * Contains all user functions
     */
    class User {
    
    /**
     * @var object $qls - Will contain everything else
     */
    var $qls;
    
    	/**
    	 * Construct class
    	 * @param object $qls - Contains all other classes
    	 * @return void
    	 */
    	function User(&$qls) {
    	    $this->qls = &$qls;
    	}
    
    	/**
    	 * Un-activates accounts that need un-activation
    	 * @return void
    	 */
    	function check_activated_accounts() {
    	    $groups_result = $this->qls->SQL->query("SELECT * FROM `{$this->qls->config['sql_prefix']}groups` WHERE `expiration_date`<>0");
    
    		// Get the groups and put them into a variable
    		while ($groups_row = $this->qls->SQL->fetch_array($groups_result)) {
                // Find the amount of seconds the admin entered
                $in_seconds = time() - ($groups_row['expiration_date'] * 86400);
                $users_result = $this->qls->SQL->query("SELECT * FROM `{$this->qls->config['sql_prefix']}users` WHERE `group_id`={$groups_row['id']} AND `activation_time`<{$in_seconds} AND `active`='yes'");
    
    			while ($users_row = $this->qls->SQL->fetch_array($users_result)) {
                    // Un-activate them
                    $this->qls->SQL->update('users',
                        array(
                            'active' => 'no'
                        ),
                        array('id' =>
                            array(
                                '=',
                                $users_row['id']
                            )
                        )
                    );
    			}
    		}
    	}
    
    	/**
    	 * Checks the password code via the GET method
    	 * @return bool
    	 */
    	function check_password_code() {
            $code = $this->qls->Security->make_safe($_GET['code']);
            $result = $this->qls->SQL->select('*',
                'password_requests',
                array('code' =>
                    array(
                        '=',
                        $code
                    )
                )
            );
            $row = $this->qls->SQL->fetch_array($result);
    
    		if ($row['id'] != '' && $row['used'] != 1) {
    		    return true;
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * This will actually change the password of the user
    	 * @return bool
    	 */
    	function change_password() {
    		// A little extra security
    		if ($this->check_password_code()) {
    		    $code = $this->qls->Security->make_safe($_GET['code']);
    
                // Retrieve the information from the database
                $result = $this->qls->SQL->select('*',
                    'password_requests',
                    array('code' =>
                        array(
                            '=',
                            $code
                        )
                    )
                );
                $row = $this->qls->SQL->fetch_array($result);
    
                // Get the user's username from the database
                $users_result = $this->qls->SQL->select('*',
                    'users',
                    array('id' =>
                        array(
                            '=',
                            $row['user_id']
                        )
                    )
                );
                $users_row = $this->qls->SQL->fetch_array($users_result);
    
                $new_password = (isset($_POST['new_password']) && $this->validate_password($_POST['new_password'])) ? $this->qls->Security->make_safe($_POST['new_password']) : false;
                $new_password_confirm = (isset($_POST['new_password_confirm']) && $_POST['new_password_confirm'] == $_POST['new_password']) ? true : false;
    
    			if ($new_password !== false && $new_password_confirm !== false) {
                    $password_hash = $this->generate_password_hash($new_password, $users_row['code']);
    
                    // Update the database
                    $this->qls->SQL->update('users',
                        array('password' => $password_hash),
                        array('id' =>
                            array(
                                '=',
                                $row['user_id']
                            )
                        )
                    );
                    $this->qls->SQL->update('password_requests',
                        array('used' => 1),
                        array('id' =>
                            array(
                                '=',
                                $row['id']
                            )
                        )
                    );
    
    			    return true;
    			}
    			else {
                    $this->change_password_error = REGISTER_PASSWORD_ERROR;
                    return false;
    			}
    		}
    		else {
                $this->change_password_error = CHANGE_PASSWORD_INVALID_CODE;
                return false;
    		}
    	}
    
    	/**
    	 * This will generate a random code
    	 * @return string of SHA1 hash
    	 */
    	function generate_random_code() {
            $hash[] = sha1(sha1(rand(1, 100)) . md5(rand(1, 100)));
            $hash[] = sha1(time() + time() . md5(time() + time()) . md5(rand()));
            $hash[] = sha1($hash[0] . $hash[1] . md5(time()));
            $hash[] = sha1($this->qls->config['user_regex'] . time());
            return sha1($hash[0] . $hash[0] . $hash[1] . $hash[2] . $hash[3] . time() . time() + time());
    	}
    
    	/**
    	 * Sends the password change email to the user
    	 * @return true on success, false on failure
    	 */
    	function send_password_email() {
    	    $username = $this->qls->Security->make_safe($_POST['username']);
    
    		if ($this->check_username_existence($username)) {
                $code = $this->generate_random_code();
                $this->qls->SQL->insert('password_requests',
                    array(
                        'user_id',
                        'code',
                        'used',
                        'date'
                    ),
                    array(
                        $this->username_to_id($_POST['username']),
                        $code,
                        0,
                        time()
                    )
                );
                $user_info = $this->fetch_user_info($username);
    
    			// Generate the link
    			if (substr($this->qls->config['cookie_domain'], 0, 1) == '.') {
    				if (substr($this->qls->config['cookie_path'], -1) == '/') {
    				    $change_link = "http://www{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}change_password.php?code={$code}";
    				}
    				else {
    				    $change_link = "http://www{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}/change_password.php?code={$code}";
    				}
    			}
    			else {
    				if (substr($this->qls->config['cookie_path'], -1) == '/') {
    				    $change_link = "http://{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}change_password.php?code={$code}";
    				}
    				else {
    				    $change_link = "http://{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}/change_password.php?code={$code}";
    				}
    			}
    
    		    $headers = "From: {$user_info['email']}\r\n";
    
    			if (mail($user_info['email'], SEND_PASSWORD_SUBJECT, sprintf(SEND_PASSWORD_BODY, $change_link), $headers)) {
    			    return true;
    			}
    			else {
    			    $this->send_password_email_error = SEND_PASSWORD_MAIL_ERROR;
    			    return false;
    			}
    		}
    		else {
    		    $this->send_password_email_error = SEND_PASSWORD_USERNAME_NON_EXISTANT;
    		    return false;
    		}
    	}
    
    	/**
    	 * Transforms a username into an ID number
    	 * @param string $username - The username to change
    	 * @return int
    	 */
    	function username_to_id($username) {
    	    $username = $this->qls->Security->make_safe($username);
    
    		// Make sure it exists
    		if ($this->check_username_existence($username)) {
                $result = $this->qls->SQL->select('id',
                    'users',
                    array('username' =>
                        array(
                            '=',
                            $username
                        )
                    )
                );
                $row = $this->qls->SQL->fetch_array($result);
                return $row['id'];
    		}
    		else {
    		    return 0;
    		}
    	}
    
    	/**
    	 * Transform a user ID into a username
    	 * @param integer $user_id - The ID to change
    	 * @return string
    	 */
    	function id_to_username($user_id) {
            $user_id = (is_numeric($user_id) && $user_id > 0) ? $user_id : 0;
            $result = $this->qls->SQL->select('username',
                'users',
                array('id' =>
                    array(
                        '=',
                        $user_id
                    )
                )
            );
            $row = $this->qls->SQL->fetch_array($result);
            return $row['username'];
    	}
    
    	/**
    	 * Validates a password
    	 * @param string $input - The input password
    	 * @return bool
    	 */
    	function validate_password($input) {
    		if (strlen($input) <= $this->qls->config['max_password'] &&
    			strlen($input) >= $this->qls->config['min_password']) {
    		    return true;
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * Validate the username according to the defined regex string.
    	 * @param string $input - The input username
    	 * @return bool
    	 */
    	function validate_username($input) {
    		if (preg_match($this->qls->config['user_regex'], $input)) {
    			if (strlen($input) <= $this->qls->config['max_username'] &&
    				strlen($input) >= $this->qls->config['min_username']) {
    			    return true;
    			}
    			else {
    			    return false;
    			}
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * Validates the user that is logged in, not logging in a user
    	 * @return bool
    	 */
    	function validate_login() {
    		if ($this->qls->Session->find_session()) {
    		    return true;
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * Fetch the user info of the user trying to login
    	 * @param string $username - The username
    	 * @return array|bool
    	 */
    	function fetch_user_info($username) {
    		if ($this->validate_username($username)) {
                // Get info from the database
                $result = $this->qls->SQL->select('*',
                    'users',
                    array('username' =>
                        array(
                            '=',
                            $username
                        )
                    )
                );
                $row = $this->qls->SQL->fetch_array($result);
                return $row;
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * Increases the number of tries by 1
    	 * @param string  $username      - The username
    	 * @param integer $current_tries - The user's current tries
    	 * @return void
    	 */
    	function update_tries($username, $current_tries) {
    		if ($this->validate_username($username)) {
                $this->qls->SQL->update('users',
                    array(
                        'tries' => ($current_tries + 1),
                        'last_try' => time()
                    ),
                    array('username' =>
                        array(
                            '=',
                            $username
                        )
                    )
                );
    		}
    	}
    
    	/**
    	 * Generates the password hash
    	 * @param string $password  - The user's password
    	 * @param string $user_code - The user's activation code
    	 * @return string
    	 */
    	function generate_password_hash($password, $user_code) {
            $hash[] = md5($password);
            $hash[] = md5($password . $user_code);
            $hash[] = md5($password) . sha1($user_code . $password) . md5(md5($password));
            $hash[] = sha1($password . $user_code . $password);
            $hash[] = md5($hash[3] . $hash[0] . $hash[1] . $hash[2] . sha1($hash[3] . $hash[2]));
            $hash[] = sha1($hash[0] . $hash[1] . $hash[2] . $hash[3]) . md5($hash[4] . $hash[4]) . sha1($user_code);
            return sha1($hash[0] . $hash[1] . $hash[2] . $hash[3] . $hash[4] . $hash[5] . md5($user_code));
    	}
    
    	/**
    	 * Compares an inputted password with the one in the database
    	 * @param string $input_password - The input password
    	 * @param string $real_password  - The user's real password
    	 * @param string $user_code      - The user's activation code
    	 * @return bool
    	 */
    	function compare_passwords($input_password, $real_password, $user_code) {
            // Generate the hash to compare them
            $input_hash = $this->generate_password_hash($input_password, $user_code);
    
    		// Actually compare them
    		if ($input_hash == $real_password) {
    		    return true;
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * Tries to login the user
    	 * @return bool
    	 */
    	function login_user() {
            $username = $_POST['username'];
            $password = $_POST['password'];
            $remember = $_POST['remember'];
            $user_info = $this->fetch_user_info($username);
    
    		if ($user_info['id'] != '') {
    			if ($user_info['tries'] < $this->qls->config['max_tries']) {
    				if ($this->compare_passwords($password, $user_info['password'], $user_info['code'])) {
    					if ($user_info['blocked'] == 'no') {
    						// They need to be active
    						if ($user_info['active'] == 'yes') {
    							if ($remember == '1') {
    							    $this->qls->Session->create_session($username, $password, $user_info['password'], true);
    							}
    							else {
    							    $this->qls->Session->create_session($username, $password, $user_info['password'], false);
    							}
    
    						    return true;
    						}
    						else {
                                if ($this->qls->config['activation_type'] == 1) {
                                    $this->login_error = LOGIN_NOT_ACTIVE_USER_CODE;
                                }
                                else {
                                    $this->login_error = LOGIN_NOT_ACTIVE_ADMIN_CODE;
                                }
    
    						    return false;
    						}
    					}
    					else {
    					    $this->update_tries($username, $user_info['tries']);
    					    $this->login_error = LOGIN_USER_BLOCKED_CODE;
    					    return false;
    					}
    				}
    				else {
    				    $this->update_tries($username, $user_info['tries']);
    				    $this->login_error = LOGIN_PASSWORDS_NOT_MATCHED_CODE;
    				    return false;
    				}
    			}
    			else {
    			    $this->login_error = LOGIN_NO_TRIES_CODE;
    			    return false;
    			}
    		}
    		else {
    		    $this->login_error = LOGIN_USER_INFO_MISSING_CODE;
    		    return false;
    		}
    	}
    
    	/**
    	 * Removes set logout cookies/sessions
    	 * @returns void
    	 */
    	function logout_user() {
    	    $session_names = array('user_id', 'user_time', 'user_unique');
    
    		if (isset($_SESSION[$this->qls->config['cookie_prefix'] . 'user_unique'])) {
                $this->qls->SQL->delete('sessions',
                    array('id' =>
                        array(
                            '=',
                            $_SESSION[$this->qls->config['cookie_prefix'] . 'user_unique']
                        )
                    )
                );
    		}
    
            // Remove all session information and unset the cookie
            $_SESSION = array();
    
    		if (isset($_COOKIE[session_name()])) {
    		    setcookie(session_name(), '', time() - 42000, '/');
    		}
    
    		if (isset($_COOKIE[$this->qls->config['cookie_prefix'] . 'user_id'])) {
    			foreach ($session_names as $value) {
    			    setcookie($this->qls->config['cookie_prefix'] . $value, 0, time() - 3600, $this->qls->config['cookie_path'], $this->qls->config['cookie_domain']);
    			}
    		}
    
    	    $this->qls->redirect($this->qls->config['logout_redirect']);
    	}
    
    	/**
    	 * Checks to see if that username already exists
    	 * @param string $username - Username to check
    	 * @return bool
    	 */
    	function check_username_existence($username) {
            if (empty($username)) {
                return false;
            }
    
    		// Check username...
    		if ($this->validate_username($username)) {
                $result = $this->qls->SQL->select('id',
                    'users',
                    array('username' =>
                        array(
                            '=',
                            $username
                        )
                    )
                );
                $row = $this->qls->SQL->fetch_array($result);
    
    			if ($row['id'] == '') {
    			    return false;
    			}
    			else {
    			    return true;
    			}
    		}
    		else {
    		    return true;
    		}
    	}
    
    	/**
    	 * Generates a new activation code
    	 * @param string $username - The user's username
    	 * @param string $password - The user's password
    	 * @param string $email    - The user's email address
    	 * @return string
    	 */
    	function generate_activation_code($username, $password, $email) {
            $hash[] = md5($username . $password . md5($email));
            $hash[] = sha1($hash[0] . $hash[0]) . md5(sha1(sha1($email) . sha1($password)) . md5($username));
            $hash[] = sha1(sha1(sha1(sha1(md5(md5('   	') . sha1(' 	'))) . sha1($password . $username))));
            $hash[] = sha1($hash[0] . $hash[1] . $hash[2]) . sha1($hash[2] . $hash[0] . $hash[1]);
            $hash[] = sha1($username);
            $hash[] = sha1($password);
            $hash[] = md5(md5($email) . md5($password));
            $hash_count = count($hash);
    
    		for ($x = 0; $x < $hash_count; $x++) {
                $random_hash = rand(0, $hash_count);
                $hash[] = sha1($hash[$x]) . sha1($password) . sha1($hash[$random_hash] . $username);
    		}
    
    	    return sha1(sha1($hash[0] . $hash[1] . $hash[2] . $hash[3]) . sha1($hash[4] . $hash[5]) . md5($hash[6] . $hash[7] . $hash[8] . sha1($hash[9])) . $password . $email);
    	}
    
    	/**
    	 * Inserts registration data into the database
    	 * @param string $username - The user's username
    	 * @param string $password - The user's password
    	 * @param string $email    - The user's email address
    	 * @return void
    	 */
    	function insert_registration_data($username, $password, $email) {
            // Generate activation code
            $generated_code = $this->generate_activation_code($username, $password, $email);
    
            // All the columns that should be in the users table
            $columns = array(
                'username',
                'password',
                'code',
                'active',
                'last_login',
                'last_session',
                'blocked',
                'tries',
                'last_try',
                'email',
                'activation_time'
            );
    
            // All the values that go with the columns
            $values = array(
                $username,
                $this->generate_password_hash($password, $generated_code),
                $generated_code,
                'no',
                0,
                '',
                'no',
                0,
                0,
                $email,
                0
            );
    
    		// Is activation required?
    		if ($this->qls->config['activation_type'] == 0) {
                $values[3] = 'yes';
                $values[10] = time();
    		}
    		elseif ($this->qls->config['activation_type'] == 1) {
    	    	$headers = "From: {$email}\r\n";
    		    // Email stuff...
    
    			if (substr($this->qls->config['cookie_domain'], 0, 1) == '.') {
    				if (substr($this->qls->config['cookie_path'], -1) == '/') {
    				    $activation_link = "http://www{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}activate.php?code={$generated_code}&username={$username}";
    				}
    				else {
    				    $activation_link = "http://www{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}/activate.php?code={$generated_code}&username={$username}";
    				}
    			}
    			else {
    				if (substr($this->qls->config['cookie_path'], -1) == '/') {
    				    $activation_link = "http://{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}activate.php?code={$generated_code}&username={$username}";
    				}
    				else {
    				    $activation_link = "http://{$this->qls->config['cookie_domain']}{$this->qls->config['cookie_path']}/activate.php?code={$generated_code}&username={$username}";
    				}
    			}
    
    		    @mail($email, ACTIVATION_SUBJECT, sprintf(ACTIVATION_BODY, $activation_link), $headers);
    		}
    
    
    	    $this->qls->SQL->insert('users', $columns, $values);
    
            // Check the invitation code
            $code = (isset($_GET['code']) && strlen($_GET['code']) == 40 && preg_match('/^[a-fA-F0-9]{40}$/', $_GET['code'])) ? $this->qls->Security->make_safe($_GET['code']) : false;
                if ($code !== false) {
                $this->qls->SQL->update('invitations',
                    array('used' => 1),
                    array('code' =>
                        array(
                            '=',
                            $code
                        )
                    )
                );
    		}
    	}
    
    	/**
    	 * This will register a user
    	 * @return bool
    	 */
    	function register_user() {
            $this->qls->Security->check_auth_registration();
    
            // Default security
            $security_check = false;
    
            /**
             * These next lines will retrieve the necessary fields. These include username,
             * password & confirmation, email & confirmation and possibly the security image.
             */
            $username = (isset($_POST['username']) && $this->validate_username($_POST['username'])) ? $this->qls->Security->make_safe($_POST['username']) : false;
            $password = (isset($_POST['password']) && $this->validate_password($_POST['password'])) ? $this->qls->Security->make_safe($_POST['password']) : false;
            $confirm_password = (isset($_POST['password_c']) && $this->qls->Security->make_safe($_POST['password_c']) == $password) ? true : false;
            $email = (isset($_POST['email']) && strlen($_POST['email']) > 6 && strlen($_POST['email']) < 256 && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) ? $this->qls->Security->make_safe($_POST['email']) : false;
            $confirm_email = (isset($_POST['email_c']) && $_POST['email_c'] == $email) ? true : false;
    
    		if ($this->qls->config['security_image'] == 'yes') {
                // The random id of the image
                $random_id = (isset($_POST['random_id']) && preg_match('/^[a-fA-F0-9]{40}$/', $_POST['random_id'])) ? $this->qls->Security->make_safe($_POST['random_id']) : false;
    
                // The security code entered by the user
                $security_code = (isset($_POST['security_code']) && preg_match('/[a-zA-Z1-9]{5,8}/', $_POST['security_code'])) ? $_POST['security_code'] : false;
    
    			if ($this->qls->Security->check_security_image($random_id, $security_code)) {
    			    $security_check = true;
    			}
    		}
    		else {
    		    $security_check = true;
    		}
    
            $_SESSION[$this->qls->config['cookie_prefix'] . 'registration_username'] = $this->qls->Security->make_safe($_POST['username']);
            $_SESSION[$this->qls->config['cookie_prefix'] . 'registration_email'] = $this->qls->Security->make_safe($_POST['email']);
            $_SESSION[$this->qls->config['cookie_prefix'] . 'registration_email_confirm'] = $this->qls->Security->make_safe($_POST['email_c']);
    
    		if ($username === false) {
    		    $this->register_error = REGISTER_USERNAME_ERROR;
    		    return false;
    		}
    
    		if ($this->check_username_existence($username)) {
    		    $this->register_error = REGISTER_USERNAME_EXISTS;
    		    return false;
    		}
    
    		if ($password === false || $confirm_password === false) {
    		    $this->register_error = REGISTER_PASSWORD_ERROR;
    		    return false;
    		}
    
    		if ($email === false || $confirm_email === false) {
    		    $this->register_error = REGISTER_EMAIL_ERROR;
    		    return false;
    		}
    
    		if ($security_check === false) {
    		    $this->register_error = REGISTER_SECURITY_ERROR;
    		    return false;
    		}
    
            $this->insert_registration_data($username, $password, $email);
            return true;
    	}
    
    	/**
    	 * Compare the code input by the user to the one in the database
    	 * @param string $input    - The input code
    	 * @param string $username - The username
    	 * @return bool
    	 */
    	function compare_codes($input, $username) {
            $result = $this->qls->SQL->select('*',
                'users',
                array('username' =>
                    array(
                        '=',
                        $username
                    )
                )
            );
            $row = $this->qls->SQL->fetch_array($result);
    
    		// Compare the codes
    		if ($row['code'] == $input) {
    		    return true;
    		}
    		else {
    		    return false;
    		}
    	}
    
    	/**
    	 * Tries to activate a user
    	 * @return bool
    	 */
    	function activate_user() {
            // validate activation code input and user id input
            $activation_code = (isset($_GET['code']) && preg_match('/[a-fA-F0-9]{40}/', $_GET['code'])) ? $this->qls->Security->make_safe($_GET['code']) : false;
            $username = (isset($_GET['username']) && $this->validate_username($_GET['username'])) ? $this->qls->Security->make_safe($_GET['username']) : false;
    
    		if ($activation_code === false) {
                $this->activate_error = ACTIVATE_CODE_NOT_VALID;
    		    return false;
    		}
    
    		if ($username === false) {
    		    $this->activate_error = ACTIVATE_USERNAME_NOT_VALID;
    		    return false;
    		}
    
    		// Compare the codes
    		if ($this->compare_codes($activation_code, $username)) {
                $this->qls->SQL->update('users',
                    array(
                        'active' => 'yes',
                        'activation_time' => time()
                    ),
                    array('username' =>
                        array(
                            '=',
                            $username
                        )
                    )
                );
    
                return true;
    		}
    		else {
                $this->activate_error = ACTIVATE_CODE_NOT_MATCH;
                return false;
    		}
    	}
    }
    

    ?

     

  3. On this page

    http://efunstudies.com/guide.php

    There is an arrow on the left that selects between tabs by:

    At the same time I have some links on the main tabs that don’t do this. After exploring it I found that that two jquery codes were doing this.  If I could figure out how the codes were being applied to the tabs I could apply them to my links, however after searching and searching, I have no idea how this theme is applying these codes to the tabs.  

    The code that goes along with the tabs is this:

    <div id="services">
    
                            <div class="container">
    
                                        <div class="information">
    
                                                    <div class="row margint50">
    
                                                                <ul class="tabbed-area col-lg-3 col-sm-3 tab-style1">
    
                                                                            <li class="active"><a href="#tab1">Step by Step Guide</a></li>
    
                                                                            <li><a href="#tab2">Before You Apply</a></li>
    
                                                                            <li><a href="#tab3">Your Application</a></li>
    
                                                                            <li><a href="#tab4">Your Acceptance</a></li>
    
                                                                            <li><a href="#tab5">Final steps</a></li>
    
                                                                            <li><a href="#tab6">Cheap Travel Tips</a></li>
    
                                                                </ul>
    

    This code is primarily CSS, right? So any ideas? Any Advice? Thanks guys!

     

    Also if it is of any use, here are the jquery codes being applied.

    function(e) {
      e.preventDefault()
      $(this).tab('show')
    }
    
    
    f = v.handle = function(e) {
      return typeof x === i || e && x.event.triggered === e.type ? t : x.event.dispatch.apply(f.elem, arguments)
    }
    
    
  4. The trick I learned, if this helps anyone. Is to simply stop using the original <select> or <label> or any such thing and create new Id's...such as #selectx an set the ID to #selectx...for example my <select> is now <select 'id='selectx'>   the later ID overrides the original command.

  5. I've been working on moving everything my mysql to mysqli, and for the most part it has been going smoothly, one exception is an error I am having now while putting it into a function. It worked just fine outside of the function, but inside I am getting an error. Here let me show you.

    <?php
    
    
    function findit($column,$table)
    {
    require_once '../dbstart.php';
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    $query = "SELECT $column FROM $table";
    $result = mysqli_query($conn, $query);
    
    $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    return $row[$column];
    
    
    /* close connection */
    mysqli_close($conn);
    }
    
    echo findit('familyname','test');
    
    
    ?> 
    

    I get

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\efun\unisearch\SQLi.php on line 15

     

    keep in mind before making it into a function I got exactly what I wanted. Any idea what I am doing wrong?

    Thanks.

  6. Yea! took me a couple hours but it's looking real good now! I'll try to convert it to my SQLi tomorrow (just programed from 8am to midnight, time to sleep). I have an idea about how to approach this, but if I run into a wall, I'll be back. :)
    Thanks again Muddy, and everyone. I couldn't have done this without you.

  7. Wow, amazing! I tested it and of course it works, of course, but when I tried to apply it to my complete search script, I just couldn't get it to work, no matter what I tried. I learned a lot from this, and I greatly appropriate it, thank you so much for taking your time to redo the script, your work is nothing less then magic! Could you give me any advice on how I could apply this correctly to my university search script. I tried so many options, but none worked correctly. I have attached a pic of what it looks like now in my search script, and the whole script is below.

     

    Capture.PNG

    <?php
    session_start();
    include("config.php");
    
    
    
    if(isset($_GET["programtype"])){
    	$programtype=$_GET["programtype"];
    	$_SESSION['programtype']=$programtype;
    	}
    else {
    	$programtype=$_SESSION['programtype'];
    	}
    	if (!isset($programtype)){
    				header("location: index.php");
    				exit;				
    		}
    		
    if(!isset($_GET["Country"])){	
    $_GET["Country"]='United States of America';
    	}
    
    	
    //////////////color
     
    function showColor($n){ 
    switch ($n){
    case 1: 
    $code = array("color" => "red", "word" => "Low");
    break;
     
    case 2:
    $code = array("color" => "green", "word" => "Medium");
             break;
             
            case 3:
             $code = array("color" => "blue", "word" => "High");
             break;
            
            case 4:
             $code = array("color" => "orange", "word" => "Very High");
             break;
             
            case 5:
    		$code = array("color" => "violet", "word" => "Extremely High!");
             break;
            
            default:
             $code = array("color" => "black", "word" => "Standard");
    }
     
        return $code;
    }
     
    $sql = "SELECT Scholarships AS colorCode FROM " . $SETTINGS["data_table"] . " WHERE id>0 LIMIT 10";
     
    $sql_result = mysql_query($sql, $connection) or die('request "Could not execute SQL query" ' . $sql);
     
    $cTable = "";
     
    if (mysql_num_rows($sql_result) > 0) {
        while ($row = mysql_fetch_assoc($sql_result)) {
            $thisColor = showColor($row["colorCode"]);
    $cTable .= "<tr><td style=color:{$thisColor['color']}>{$thisColor['word']}</td></tr>";
        }
    } 
    else {
        $cTable .= "<tr><td>No Results</td></tr>";    
    }
     $htmlBody =$cTable;
    
     
    ?>
    
    
    
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>University Search</title>
    <style>
    BODY, TD {
    	font-family:Arial, Helvetica, sans-serif;
    	font-size:12px;
    }
    </style>
    </head>
    
    
    <body>
    
    <form id="form1" name="form1" method="get" action="search.php">
    <label>Country</label>
    <select name="Country">
    <option value="<?php echo $_GET["Country"];?>"><?php echo $_GET["Country"];?></option>
    <option value='United Kingdom'>United Kingdom</option><br />
    <option value='United States of America'>United States of America</option>
    <option value='Argentina'>Argentina</option><br />
    <option value='Australia'>Australia</option><br />
    <option value='Austria'>Austria</option><br />
    <option value='Bangladesh'>Bangladesh</option><br />
    <option value='Belarus'>Belarus</option><br />
    <option value='Belgium'>Belgium</option><br />
    <option value='Brazil'>Brazil</option><br />
    <option value='Canada'>Canada</option><br />
    <option value='Chile'>Chile</option><br />
    <option value='China'>China</option><br />
    <option value='Colombia'>Colombia</option><br />
    <option value='Cyprus'>Cyprus</option><br />
    <option value='Czech Republic'>Czech Republic</option><br />
    <option value='Denmark'>Denmark</option><br />
    <option value='Egypt'>Egypt</option><br />
    <option value='Estonia'>Estonia</option><br />
    <option value='Finland'>Finland</option><br />
    <option value='France'>France</option><br />
    <option value='Germany'>Germany</option><br />
    <option value='Ghana'>Ghana</option><br />
    <option value='Greece'>Greece</option><br />
    <option value='Hong Kong'>Hong Kong</option><br />
    <option value='Hungary'>Hungary</option><br />
    <option value='Iceland'>Iceland</option><br />
    <option value='India'>India</option><br />
    <option value='Indonesia'>Indonesia</option><br />
    <option value='Iran'>Iran</option><br />
    <option value='Israel'>Israel</option><br />
    <option value='Italy'>Italy</option><br />
    <option value='Japan'>Japan</option><br />
    <option value='Jordan'>Jordan</option><br />
    <option value='Kenya'>Kenya</option><br />
    <option value='Latvia'>Latvia</option><br />
    <option value='Lebanon'>Lebanon</option><br />
    <option value='Lithuania'>Lithuania</option><br />
    <option value='Luxembourg'>Luxembourg</option><br />
    <option value='Macau'>Macau</option><br />
    <option value='Malaysia'>Malaysia</option><br />
    <option value='Mexico'>Mexico</option><br />
    <option value='Morocco'>Morocco</option><br />
    <option value='Netherlands'>Netherlands</option><br />
    <option value='New Zealand'>New Zealand</option><br />
    <option value='Nigeria'>Nigeria</option><br />
    <option value='Norway'>Norway</option><br />
    <option value='Oman'>Oman</option><br />
    <option value='Pakistan'>Pakistan</option><br />
    <option value='Poland'>Poland</option><br />
    <option value='Portugal'>Portugal</option><br />
    <option value='Qatar'>Qatar</option><br />
    <option value='Republic of Ireland'>Republic of Ireland</option><br />
    <option value='Romania'>Romania</option><br />
    <option value='Russian Federation'>Russian Federation</option><br />
    <option value='Saudi Arabia'>Saudi Arabia</option><br />
    <option value='Serbia'>Serbia</option><br />
    <option value='Singapore'>Singapore</option><br />
    <option value='Slovakia'>Slovakia</option><br />
    <option value='Slovenia'>Slovenia</option><br />
    <option value='South Africa'>South Africa</option><br />
    <option value='South Korea'>South Korea</option><br />
    <option value='Spain'>Spain</option><br />
    <option value='Sweden'>Sweden</option><br />
    <option value='Switzerland'>Switzerland</option><br />
    <option value='Taiwan'>Taiwan</option><br />
    <option value='Thailand'>Thailand</option><br />
    <option value='Turkey'>Turkey</option><br />
    <option value='Uganda'>Uganda</option><br />
    <option value='Ukraine'>Ukraine</option><br />
    <option value='United Arab Emirates'>United Arab Emirates</option><br />
    </select>
    
    
    <label>How do you want to sort the universities?</label>
    <select name="sorthow" id="sorthow"  >
    <option selected="" value="">---Select---</option>
    <option value="<?php echo $programtype ?>"><?php echo $programtype ?> Ranking</option>
    <option value='rank'>Overall Ranking</option>
    <option value="`Immigration rate`">Immigration rate</option>
    <option value="`Income greater then average`">Income</option>
    <option value="Scholarships">Scholarships</option>
    <option value="TA">Teaching Asstantships</option>
    <option value="RA">Research Asstantships</option>
    <option value="satisfaction">Student Satisfaction</option>
    </select>
    
    <label>What level of ramnking are you looking for?</label>
    <select name="number" id="number"  >
    <option selected="" value="">---Select---</option>
    <option value='0'>The Best of the best</option>
    <option value="25">Top 25+</option>
    <option value="50">Top 50+</option>
    <option value="75">Top 75+</option>
    <option value="100">Top 100+</option>
    </select>
    
    
    <input type="submit" name="button" id="button" value="Search" />
    
    </form>
    <br /><br />
    <table width="700" border="1" cellspacing="0" cellpadding="4">
      <tr>
        <td width="191" bgcolor="#CCCCCC"><strong><button onclick="odds()">Odds of Getting Accepted</button></strong></td>
    	<td width="191" bgcolor="#CCCCCC"><strong>University</strong></td>
        <td width="113" bgcolor="#CCCCCC"><strong>Country</strong></td>
        <td width="159" bgcolor="#CCCCCC"><strong><button onclick="programrank()"><?php echo $programtype ?> Ranking</button></strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong><button onclick="rank()">Overall Rank</button></strong></td>
    	<td width="191" bgcolor="#CCCCCC"><strong><button onclick="immigrant()">Immigration rate</button></strong></td>
    	<td width="191" bgcolor="#CCCCCC"><strong><button onclick="Income()">Income</button></strong></td>
    	<td width="191" bgcolor="#CCCCCC"><strong><button onclick="Scholarships()">Scholarships<br></button></strong></td>
    <!--	<td width="191" bgcolor="#CCCCCC"><strong><button onclick="Teaching()">Teaching Asstantships</button></strong></td>
    	<td width="191" bgcolor="#CCCCCC"><strong><button onclick="Research()">Research Asstantships</button></strong></td>
    	<td width="191" bgcolor="#CCCCCC"><strong><button onclick="Satisfaction()">Student Satisfaction</button></strong></td>
    --> 
     </tr>
      
    
    
    
    
    
    
      
      
      
      
    <?php
    $number='';
    If ((($_GET["sorthow"]) == 'rank') || (($_GET["sorthow"]) == $programtype)){
    $upordown="ASC";
    	if(isset($_GET['number'])){$number = " AND ". mysql_real_escape_string($_GET['sorthow']). " >=". mysql_real_escape_string($_GET['number'])." ";}
    }
    else {$upordown="DESC";}
    	$search_Country = " Country='". mysql_real_escape_string($_GET['Country']). "'";	
    	$search = " ORDER BY '". mysql_real_escape_string($_GET['sorthow']). "' ".$upordown;	
    
    
    $sorthow=mysql_real_escape_string($_GET["sorthow"]);
    
    //////////////feedback
    
    if ($_GET["sorthow"]<>'') {
    	$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE ".$search_Country. $number. $search. " LIMIT 10";
    } else {
    	$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE ".$search_Country." LIMIT 300";
    }
    echo "SELECT * FROM unidata WHERE rank >= 75 AND Country='Australia' ORDER BY 'rank' ASC<br>";
    echo $sql;
    ///////////////////
    $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
    if (mysql_num_rows($sql_result)>0) {
    	while ($row = mysql_fetch_assoc($sql_result)) {
    
    ?>
      <tr>
        <td>'Members Only'<br> <a href="signup.php">Sign Up now<i class="icon-long-arrow-right"></i></a></td>
    	<td><?php echo $row["University"]; if(isset($row["City"])){echo $row["City"]; }?></td>
        <td><?php echo $row["Country"];?></td>
        <td><?php echo $row[$programtype]; ?></td>
        <td><?php echo $row["Rank"]; ?></td>
        <td><?php echo $row["Immigration rate"]; ?></td>
    	<td><?php echo $row["Income greater then average"]; ?></td>
    <?php   echo $htmlBody; ?>
    
    	
    	
    
      </tr>
      
      <?php
    
    }}
    ?>
     
    </table>
    
    
    
    <script>
    function odds() {
        alert("Your odds of being accepted into a university depend on a lot of factors, including:	\n Grades\n Test scores\n The quality of your References\nThe quality and information in your Personal Statement\n Your Work and Volunteer Experience\n\nWe use a complex algorithm to match your all of these to the requirements of each school. If you want to know our algorithm, here it is:\n Odds=[ð‘¤ð»24(S24+0.4ð»14ð´+0.4ð»24ð‘ƒ)+ð‘¤ð»47(ð»38+0.4L48ð´+0.4ð»48ð‘ƒ)\n+ð‘¤ð»72(ð»72+0.4ð»72ð´+0.4ð»72ð‘ƒ)+ð‘¤ð·(ð·+0.4ð·ð´+0.4ð·ð‘ƒ)\n+ð‘¤ð‘€ð‘€0.3+ð‘¤ð¿ð¿0.05+ð‘¤ð‘…ð‘…20,000+ð‘¤ð‘‡ð‘‡+ð‘¤ð‘„ð‘„0.02+ð‘¤ðºðº0.04]×ð‘†");
    }
    function programrank() {
        alert("The <?php echo $programtype; ?>ranking sorts the best <?php echo $programtype; ?> university programs. This ranking IS MUCH more important than the Overall Ranking");
    }
    function rank() {
        alert("The Overall Ranking looks at the total ranking of all programs a university has and sums them up. While this ranking can be helpful for sorting universities, it should not be the main focus of which university you choose as it unfairly gives advantages to larger universities with more programs also ignores many specialty programs");
    	}
    function immigrant() {
        alert("Our Immigration Rate Score is based on the past success of applications who graduating from this school applying for and being accepted as Immigrants to this the county. While the quality of the university does make a difference, do keep in mind that some countries have much higher immigration rates than others.");
    	}
    function Income() {
        alert("We based this score on the average income of schools graduates and the standard income of the countries the school is in. The rating ranges from making the same as the average for that country to making much higher income then the average in the country");
    	}
    function Scholarships() {
        alert("This list shows is based on the amount of scholarships in total available for the student population. The more scholarships available, the greater your chance of getting one or many.");
    	}
    function Teaching() {
        alert("This list shows is based on the amount of Teaching Assistantships for Graduate (masters and PhD) students available for the student population. The more Teaching Assistantships available, the greater chance of you getting one.");
    	}
    function Research() {
        alert("This list shows is based on the amount of Research Assistantships for Graduate (masters and PhD) students available for the student population. The more Research Assistantships available, the greater chance of you getting one.");
    	}
    function Satisfaction() {
        alert("This Score measures the overall Self-reported satisfaction from students at that school.");
    	}
    
    	
    </script>
    
    
    
    
    
    
    </body>
    </html>
    <?php
    
        
    
    ?>
    
  8. HAHA, sorry about that, twas an accident. efunstudies.com/q/register2.php :D

    Well In this link the UNI search box at the top right is more or less how I want it, quite condensed with width set at auto and margins at 0. However in the link that was correct earlier (http://efunstudies.com/guide.php) the CSS's are battling for domination and one overrides the other, changing my margins and width. The issue revolved around but I am not sure what to do to fix this, I tried many options, but nothing thus far has worked.

  9. I have a CSS issue where one code is overrunning another, I tried to fix it but I failed. Here is my code for my search bar in the upper right area. I know the issue has to do with <style> and I tried to correct it but failed every time.

     

    
    <style type="text/css">
    #tabeluni {
       border: 1px solid silver;
       border='1' cellpadding='4'
    }
    #buttonx{
        background: linear-gradient(#ffbc00 5%, #ffdd7f 100%);
        border: 1px solid #red;
        color: #524f49;
        cursor: pointer;
        width: 100%;
        border-radius: 2px;
        font-weight:bold;
        font-size:15px;
    }
    
    #button:hover{
        background: linear-gradient(#ffdd7f 5%, #ffbc00 100%);
    }
    #unitext{
        color: #f2836b;
        font-size: 15px;
        text-align: center;
    }
    labelx{
        display: inline-block;
        margin-bottom: 5px;
        font-weight: bold;
    }
    
    selectx{
        margin-bottom: 0px;
        margin-top: 0px;
        width: auto;
        height: auto;
        font-size: 16px;
        font-family: cursive;
    }
    </style>
    <?php
    $unisearchbar = "<div id='selectx'><table id='tabeluni'><tr><td>
    <div align='Left'>
                        <div><form action='unisearch/search.php' method='post'>
                        <div id='unitext'>University Search</div>
                        <label>Catagory</label>
                        <label  for='programtype'></label>
                        <select  name='programtype' id='programtype' required >
                        <option selected='selected' value=''>---Select---</option>
                        <option value='Social Science'>Social Science</option>
                        <option value='Arts '>Arts </option>
                        <option value='Humanities and Liberal Studies '>Humanities </option>
                        <option value='Engineering '>Engineering </option>
                        <option value='Technology '>Technology </option>
                        <option value='Health '>Health </option>
                        <option value='Biology and Life Sciences '>Biology</option>
                        <option value='Physical Sciences '>Physical Sciences </option>
                        </select>
    <br>
                        <labelx>Country</labelx>
                        <select name='Country'>
                        <option value=''>--</option>
                        <option value='United Kingdom'>United Kingdom</option><br />
                        <option value='United States of America'>United States of America</option>
                        <option value='Argentina'>Argentina</option><br />
                        <option value='Australia'>Australia</option><br />
                        <option value='Austria'>Austria</option><br />
                        <option value='Bangladesh'>Bangladesh</option><br />
                        <option value='Belarus'>Belarus</option><br />
                        <option value='Belgium'>Belgium</option><br />
                        <option value='Brazil'>Brazil</option><br />
                        <option value='Canada'>Canada</option><br />
                        <option value='Chile'>Chile</option><br />
                        <option value='China'>China</option><br />
                        <option value='Colombia'>Colombia</option><br />
                        <option value='Cyprus'>Cyprus</option><br />
                        <option value='Czech Republic'>Czech Republic</option><br />
                        <option value='Denmark'>Denmark</option><br />
                        <option value='Egypt'>Egypt</option><br />
                        <option value='Estonia'>Estonia</option><br />
                        <option value='Finland'>Finland</option><br />
                        <option value='France'>France</option><br />
                        <option value='Germany'>Germany</option><br />
                        <option value='Ghana'>Ghana</option><br />
                        <option value='Greece'>Greece</option><br />
                        <option value='Hong Kong'>Hong Kong</option><br />
                        <option value='Hungary'>Hungary</option><br />
                        <option value='Iceland'>Iceland</option><br />
                        <option value='India'>India</option><br />
                        <option value='Indonesia'>Indonesia</option><br />
                        <option value='Iran'>Iran</option><br />
                        <option value='Israel'>Israel</option><br />
                        <option value='Italy'>Italy</option><br />
                        <option value='Japan'>Japan</option><br />
                        <option value='Jordan'>Jordan</option><br />
                        <option value='Kenya'>Kenya</option><br />
                        <option value='Latvia'>Latvia</option><br />
                        <option value='Lebanon'>Lebanon</option><br />
                        <option value='Lithuania'>Lithuania</option><br />
                        <option value='Luxembourg'>Luxembourg</option><br />
                        <option value='Macau'>Macau</option><br />
                        <option value='Malaysia'>Malaysia</option><br />
                        <option value='Mexico'>Mexico</option><br />
                        <option value='Morocco'>Morocco</option><br />
                        <option value='Netherlands'>Netherlands</option><br />
                        <option value='New Zealand'>New Zealand</option><br />
                        <option value='Nigeria'>Nigeria</option><br />
                        <option value='Norway'>Norway</option><br />
                        <option value='Oman'>Oman</option><br />
                        <option value='Pakistan'>Pakistan</option><br />
                        <option value='Poland'>Poland</option><br />
                        <option value='Portugal'>Portugal</option><br />
                        <option value='Qatar'>Qatar</option><br />
                        <option value='Republic of Ireland'>Republic of Ireland</option><br />
                        <option value='Romania'>Romania</option><br />
                        <option value='Russian Federation'>Russian Federation</option><br />
                        <option value='Saudi Arabia'>Saudi Arabia</option><br />
                        <option value='Serbia'>Serbia</option><br />
                        <option value='Singapore'>Singapore</option><br />
                        <option value='Slovakia'>Slovakia</option><br />
                        <option value='Slovenia'>Slovenia</option><br />
                        <option value='South Africa'>South Africa</option><br />
                        <option value='South Korea'>South Korea</option><br />
                        <option value='Spain'>Spain</option><br />
                        <option value='Sweden'>Sweden</option><br />
                        <option value='Switzerland'>Switzerland</option><br />
                        <option value='Taiwan'>Taiwan</option><br />
                        <option value='Thailand'>Thailand</option><br />
                        <option value='Turkey'>Turkey</option><br />
                        <option value='Uganda'>Uganda</option><br />
                        <option value='Ukraine'>Ukraine</option><br />
                        <option value='United Arab Emirates'>United Arab Emirates</option><br />
    
                        </select>
                        
                        
                         <input type='submit' name='button' id='buttonx' value='Search' />
                
                    </form></div></div></td></tr></table></div>
                    
                    "?>
    




    You can see the search bar working correctly here

    http://efunstudies.com/guide.php

     



    and you can see it working incorrectly because of CSS conflicts here

    http://localhost/efun/q/register2.php

     

  10. Hey all, I've been working on this and a few of you have been helping me on it, but I want to post it here so all is clear. First the code.

    <?php
    session_start();
    include("config.php");
    
    
    
    function showColor($number)
    {
        if ($number == 1) {
            $color = "red";
            $word  = "Low";
        }
        if ($number == 2) {
            $color = "green";
            $word  = "Medium";
        }
        if ($number == 3) {
            $color = "blue";
            $word  = "High";
        }
        if ($number == 4) {
            $color = "orange";
            $word  = "Very High";
        }
        if ($number == 5) {
            $color = "violet";
            $word  = "Extremely High!";
        }
        return "<td style='color:$color';>$word</td>";
    }
    
    
    $sql = "SELECT * FROM " . $SETTINGS["data_table"] . " WHERE id>0 LIMIT 10";
    
    $sql_result = mysql_query($sql, $connection) or die('request "Could not execute SQL query" ' . $sql);
    
    $Scholarships = array();
    
    if (mysql_num_rows($sql_result) > 0) {
        while ($row = mysql_fetch_assoc($sql_result)) {
            
            $Scholarships[] = $row["Scholerships"];
    
        }
        
    } else {
        
        $Scholarships[] = "fail";
        
    }
    
    ?>
    
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Show color</title>
    </head>
    
    <body>
    <div>
    <table style="width:191px;">
      <tr>
    <?php
    print_r ($Scholarships); 
    foreach ($Scholarships as $thecolor) {
        echo showColor($thecolor);}
    
    
    	
        
    
    
    ?>
    
      </tr>
    </table>
    </div>
    
    </body>
    
    </html>
    

    Print R gives me this

     

     

    Array ( [0] => 3 ) Array ( [0] => 3 [1] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 [7] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 [7] => 3 [8] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 [7] => 3 [8] => 3 [9] => 3 )

     

    and foreach gives me this.

    High High High High High High High High High High

     

    The issue is I need the table created by the foreach to create me 1 row and 10 columns. I am not sure how to get that.

    Any Advice?

     

  11. You would be better starting a new thread for this, but basically you're just using the $Scholerships array instead of the $row array - so for example, assuming you have column names "fistName, lastName, enroleDate, colorCode" you can do the following:

    foreach($Scholership as $record){
    $tableRow = <<<TABLE_ROW
    <tr style="color:{$record['colorCode']}"><td>{$record['firstName']}</td><td>{$record['lastName']}</td><td>{$record['enroleDate']}</td></tr>
    TABLE_ROW;
    echo $tableRow;
    }

    This obviously doesn't connect with the code that @QuickOldCar has already provided and isn't meant as anything more than an example of how you can handle the information in the array.

     

    Also - I would like to take this chance to discourage you from using SELECT * for queries, name each column that you are retrieving from the table.

    Muddy I tried to use your advice, but I couldn't get it to work. I print r the Array, and my results were :

     

    Array ( [0] => 3 ) Array ( [0] => 3 [1] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 [7] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 [7] => 3 [8] => 3 ) Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 [5] => 3 [6] => 3 [7] => 3 [8] => 3 [9] => 3 )

    Based on this is there any advice you can give.  On the bright side I did fix every other problem with this database search script that I ran into.

     

  12. Also - I would like to take this chance to discourage you from using SELECT * for queries, name each column that you are retrieving from the table.

    Muddy, Could you tell me why? Also thanks for the code and suggestions. I'll look into it.

  13. Hey Muddy,

    Not so much SQL here...it seems....but I really want to get it working before moving to mysql as that will also give me a lot of problems.

    at current if

        <td><?php echo $row["Arts"]; ?></td>

    it works just fine.

    But if

    $programtype="Arts";

        <td><?php echo $row[$programtype]; ?></td>

    It fails and tells me it cant find Arts.

    No idea what is wrong.

  14. Hey guys, here is my page to search mySQL database. It mostly works...but there are some issues.

    First     $programtype can be set on this or another page. And it works, but when I try

     

        <td><?php echo $row[$programtype]; ?></td>

    toward to the bottom, it never works. I am not sure why.

    Next for whatever reason It seems my sorting only works with overall rank, nothing else, any idea?

    Thanks

    PS. I will switch to mysqli after i fix this issue.

     

     

     

    <?php
    session_start();
    //error_reporting(0);
    include("config.php");

    if(isset($_POST["programtype"])){
        $programtype=$_POST["programtype"];
        $_SESSION['programtype']=$programtype;
        }
    else {
        $programtype=$_SESSION['programtype'];
        }
        if (!isset($programtype)){
                    header("location: index.php");
                    exit;                
            }

    ?>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>University Search</title>
    <style>
    BODY, TD {
        font-family:Arial, Helvetica, sans-serif;
        font-size:12px;
    }
    </style>
    </head>


    <body>

    <form id="form1" name="form1" method="post" action="search.php">
    <label>Country</label>
    <select name="Country">
    <option value="">--</option>
    <?php
        $sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY Country ORDER BY Country";
        $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
        while ($row = mysql_fetch_assoc($sql_result)) {
            echo "<option value='".$row["Country"]."'".($row["Country"]==$_REQUEST["Country"] ? " selected" : "").">".$row["Country"]."</option>";
        }
    ?>

    </select>
    <label>How do you want to sort the universities?</label>
    <select name="sorthow" id="sorthow"  >
    <option selected="selected" value="">---Select---</option>
    <option value="`$programtype`"><?php echo $programtype ?> Ranking</option>
    <option value='rank'>Overall Ranking</option>
    <option value="`Immigration rate`">Immigration rate</option>
    <option value="`Income greater then adverage`">Income</option>
    <option value="`Scholerships`">Scholerships</option>
    <option value="`TA`">Teaching Asstantships</option>
    <option value="`RA`">Research Asstantships</option>
    <option value="`satisfaction`">Student Satisfaction</option>
    </select>


    <input type="submit" name="button" id="button" value="Search" />

    </form>
    <br /><br />
    <table width="700" border="1" cellspacing="0" cellpadding="4">
      <tr>
        <td width="191" bgcolor="#CCCCCC"><strong>Odds of Getting Accepted</strong></td>
        <td width="113" bgcolor="#CCCCCC"><strong>Country</strong></td>
        <td width="159" bgcolor="#CCCCCC"><strong><?php echo $programtype ?> Ranking</strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong>Overall Rank</strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong>Income</strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong>Immigration rate</strong></td>    
        <td width="191" bgcolor="#CCCCCC"><strong>Scholerships</strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong>Teaching Asstantships</strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong>Research Asstantships</strong></td>
        <td width="191" bgcolor="#CCCCCC"><strong>Student Satisfaction</strong></td>
      </tr>
    <?php
    ///country
    if ($_REQUEST["Country"]<>'') {
        $search_Country = " AND Country='".mysql_real_escape_string($_REQUEST["Country"])."'";    
    }

    $sorthow=mysql_real_escape_string($_REQUEST["sorthow"]);
    //////////////feedback

    if ($_REQUEST["sorthow"]<>'') {
        $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE ".  " '".mysql_real_escape_string($_REQUEST["sorthow"])."'".$search_country." LIMIT 10";
    } else {
        $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE id>0".$search_country." LIMIT 10";
    }

    ///////////////////
    $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
    if (mysql_num_rows($sql_result)>0) {
        while ($row = mysql_fetch_assoc($sql_result)) {
    ?>
      <tr>
        <td>'Members Only'<br> <a href="signup.php">Sign Up now<i class="icon-long-arrow-right"></i></a></td>
        <td><?php echo $row["Country"]; ?></td>
        <td><?php echo $row[$programtype]; ?></td>
        <td><?php echo $row["Rank"]; ?></td>
        <td><?php echo $row["Immigration rate"]; ?></td>
        <td><?php echo $row["Income greater then adverage"]; ?></td>
        <td><?php echo $row["Scholerships"]; ?></td>
        <td><?php echo $row["TA"]; ?></td>
        <td><?php echo $row["RA"]; ?></td>
        <td><?php echo $row["satisfaction"]; ?></td>
      </tr>
    <?php
        }
    } else {
    ?>
    <tr><td colspan="5">Sorry, we didn't find anything, try again.</td>
    <?php    
    }
    ?>
    </table>




    </body>
    </html>

  15. Thanks again, for the help with the code and the spelling :)

    Right now everything that will be changed is a number.

    As my mySQL being deprecated - my plan is to get this to work, then go back and change it to mysqli, which I am still unfamiliar with.

    While this works as is I ran into a tiny issue.

    I want to display the scholarships as a row. When I pulled the data from     while ($row = mysql_fetch_assoc($sql_result)) {

    they were in a format that worked well for inserting them into columns, now as an array I don't know how to inset them into a column in a working way. Any idea?

    Thanks

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