Jump to content

Checking url segments against database


Xtremer360

Recommended Posts

I'm trying to figure out where I need to run my function that gets both parameters and checks them against the database and then if the result returns true then the user validating.

 

 

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Activate extends CI_Controller { 

public function __construct()
    {
        parent::__construct();
        $this->load->library('auth');
    }
    
    public function index($param1 = NULL, $param2 = NULL)
{
	//Config Defaults Start
	$msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
	$cssPageAddons = '';//If you have extra CSS for this view append it here
	$jsPageAddons =  '';//If you have extra JS for this view append it here
	$metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
	$siteTitle = '';//alter only if you need something other than the default for this view.
	//Config Defaults Start


	//examples of how to use the message box system (css not included).
	//$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');

	/**********************************************************Your Coding Logic Here, Start*/

        $x = 0;
        if(($param1 !== NULL)&&($param2 !== NULL))
        {
       
            //params not null yay..
            if((isset($param1))&&((trim($param1) !== '')||(!empty($param1))))
            {
                if(!is_numeric($param1))
                {
                  $x++;
                }
            }
            if((isset($param2))&&((trim($param2) !== '')||(!empty($param2))))
            {
                if(!preg_match('/^[A-Za-z0-9]+$/', $param2))
                {
                  $x++;
                }
            }
       
       
            if($x !== 0)
            {
               $bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
               $message = 'User was not activated successfully! Please try again with the right credentials!';
            }
            else
            {
               $bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
               $message = 'User was activated successfully! You may now login!';
            }
       
        }
        else
        {
            show_404();
        }
        $this->data['message'] = $message;
        $bodyType = "full";//type of template	

	/***********************************************************Your Coding Logic Here, End*/

	//Double checks if any default variables have been changed, Start.
	//If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.      
	if(count($msgBoxMsgs) !== 0)
	{
		$msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
	}
	else
	{
		$msgBoxes = array('display' => 'none');
	}

	if($siteTitle == '')
	{
		$siteTitle = $this->metatags->SiteTitle(); //reads 
	}

	//Double checks if any default variables have been changed, End.

	$this->data['msgBoxes'] = $msgBoxes;
	$this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
	$this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
	$this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
    $this->data['bodyType'] = $bodyType;
    $this->data['bodyContent'] = $bodyContent;
	$this->load->view($this->config->item('defaultTemplate') .'/usermanagement/index', $this->data);
}
        
}

/* End of file activate.php */ 
/* Location: ./application/controllers/activate.php */ 

Link to comment
https://forums.phpfreaks.com/topic/262984-checking-url-segments-against-database/
Share on other sites

Sorry its 6 am here and I haven't slept for a while due to work. What I meant to say was I'm trying to figure out where in my code I should perform another if statement to run the two parameters inside of a function against my database to see if they match.

The big issue I see first off is how you're passing parameters to your index method.  In CI the methodology is controller/method/params and the index() serves as the controller itself, so adding any parameters is going to fail, unless you use a _remap().

 

Now, what you ought to do is add an activate() to account and pass your params that way.

 

account/activate/session_or_activation_code

 

To which you can

// Set up the data
$data = array(
'user_activation'	=> $this->uri->segment(3, '')
);

// Retrieve the user
if($user = $this->users->get_user($data))
{
// User exists, set up the data
$data = array(
	'user_activation'	=> 1
);

// Update the user in the database
$this->users->update_user($user->user_id, $data);

// Send player a welcome message
$this->messenger->welcome_msg($user);			

// Assign page title
$page->title = "Activation Success";

// Assign page content
$page->content = 'Your account has been activated!' . br(2) . 'You should now be able to ' . anchor('account/login', 'login') . ' and interact with the site.' . br(2) . 'Thanks for Registering!' . br() . SITE_NAME . br() . anchor(site_url());

// Create a reference to page
$this->data->page =& $page;

// Load the page view
$this->load->view('page', $this->data);
}
else
{ ... }

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.