Welcome Guest, Not a member yet? Register   Sign In
uri->segment object help!!
#1

[eluser]miky4e[/eluser]
hello,

I have a problem with uri->segment() object in my web application.

This is my url

Code:
/index.php/account/d41d8cd98f00b204e9800998ecf8427e

Where account is class Account extends Controller and index() function get uri element... but, doesn't work!

Code:
404 Page Not Found
The page you requested was not found.

This is my error: 404 not found!?!

For simple example, this is my code:
Code:
function index()
    {
        if($this->uri->segment(2) == 'd41d8cd98f00b204e9800998ecf8427e')
        {
            echo "Ok";
        }
    }

Where is the problem???

Thanks Wink

PS. I wanna comparate session_id (in login file) with account/session_id in account class Wink
#2

[eluser]xwero[/eluser]
The second segment in CI urls is by default the controller method so you need routing or the _remap function to alter this behaviour.
#3

[eluser]miky4e[/eluser]
Thanks for reply, but the error is another!!!

My code line:

Code:
$session = $this->session->set_userdata('session_id', $this->input->post('username'));

doesn't work correctly! The session variable is empty!
Why?? This is a problem!! Wink
#4

[eluser]xwero[/eluser]
I don't see what the last snippet has to to with the starter topic? If you want to compare the current session id with the id in the url then you have to do something like
Code:
if($this->uri->segment(2) == $this->session->userdata('id')){}

The last snippet sets a session variable but the output is void so the session variable will always be empty. Additionally you haven't defined the session key to identify the value or the $_POST['username'] would have to be an array which is unlikely.
#5

[eluser]miky4e[/eluser]
No, doent' work...

One moment, I paste my simple script:

1) login.php

Code:
if($query->num_rows() == 1)
            {
                $session = $this->session->set_userdata('session', .$this->input->post('username'));
                
                // redirect...
                redirect('members/account/'.$session);
            }

I want to use $this->session->userdata('session' that md5(username_value)

and 2) members.php

Code:
function index()
    {        
        if($this->session->userdata('session') == FALSE)
        {
            $this->load->view('login');
            return false;
        }
    }
    
    function account()
    {        
        // checking session status...
        if($this->uri->segment(3) == $this->session->userdata('session'))
        {
            echo "Welcome, boy";
        }
        else
        {
            $this->load->view('login');
            return false;
        }
    }

Thanks for time and reply Wink
#6

[eluser]miky4e[/eluser]
Ok, I have modify the code and use this sample:

Code:
// setting up session name
                $this->session->set_userdata('session', $this->input->post('username'));
                
                // redirect...
                redirect('members/account/'.md5($this->input->post('username')));
#7

[eluser]xwero[/eluser]
the set_userdata method returns nothing, not even a boolean to check if the key was actually added/changed or not. That is why i said the session variable will always be empty. You will have to do something like this
Code:
$session = md5($this->input->post('username'));
$this->session->set_userdata('session', $session);
redirect('members/account/'.$session);
#8

[eluser]miky4e[/eluser]
[quote author="xwero" date="1222704662"]the set_userdata method returns nothing, not even a boolean to check if the key was actually added/changed or not. That is why i said the session variable will always be empty. You will have to do something like this
Code:
$session = md5($this->input->post('username'));
$this->session->set_userdata('session', $session);
redirect('members/account/'.$session);
[/quote]

Thank you boy! The script work fine Wink

Thanks and sorry for your time_usage(); (LOL)
#9

[eluser]Colin Williams[/eluser]
Quote:Thank you boy! The script work fine

Translation: "I copied and pasted and it worked. I'm a programmer! Woohoo!"

Just teasing you, miky4e ;-)
#10

[eluser]miky4e[/eluser]
[quote author="Colin Williams" date="1222705554"]
Quote:Thank you boy! The script work fine

Translation: "I copied and pasted and it worked. I'm a programmer! Woohoo!"

Just teasing you, miky4e ;-)[/quote]

No, absolutely Wink I used my script and my code ! Wink




Theme © iAndrew 2016 - Forum software by © MyBB