Can any one explain opencart session in API module? - php

Session not showing while dump the following session value.
print_r($this->session->data['api_id']);die;
in api/cart/add module.

session variable api_id is set from the admin side. When the admin create or modify any order it create the different session for API user by api login. Check
admin/controller/sale/order.php file

Related

Do not check session on specific page

I am using sessions to check if the user is logged in. In my project, there are some pages, where session check is not required i.e user can access it without logging in. How I disable session check on selective pages? Instead of writing say session_check on every page that needs session, i want to know if there is a way to implement no_session_check() on selected pages. As the number of pages that require session check are more than pages that do not work. I am using codeigniter. Thanks
First you created the session checking function in library file .. if u want session on that controller just call that library function..
Refer this link:

Sessions in CodeIgniter hinder each other

I'm making a CMS using CodeIgniter. I'm using modules to separate the admin part of the site from the normal site. I make use of session to store some data, this is working great but i got 1 problem.
When i login in the Admin panel it makes a session so I know I’m logged in. When I go to the normal site and return to admin and refresh my page I’m logged out. It seems like when I go to the normal site it first clears the session or it overwrite the old session. I think this comes because of the session name used by CodeIgniter.
now my question :p
Is it possible to set different session names for the admin module and the normal site?
I hope I have made ​​myself clear
Best practice if you handle session with db in CI
yes it's possible please use seperate session for both and on logout unset seperate session what session you want to unset.
like you create session for front:-
$this->session->set_userdata('user_account_login',$data);
on logout you need :-
$this->session->unset_userdata('user_account_login');
same for admin but in different var :-
$this->session->set_userdata('admin_account_login',$data);
on logout you need :-
$this->session->unset_userdata('admin_account_login');

Using a php application session into another codeigniter application

I am using a existing php application which has different interfaces like admin, agent and customer.
I have created a new agent interface using codeignitor. FOr login into agent portal, I am using the existing agent login page from old application but after login is successful my new agent interface is supposed to be loaded.
In the old application, there are sessions used and the agent_id is stored in the session variable.
when I am trying to use this session variable in my new code, I get an error message ...variable can't be found. How can I use the session variable from my first application into my new interface?
when I print the session name in my first application and in one of new codeignitor code page,, I can see both the sessions are different. I think this is the problem because codeignitor manages its session.
I searched on the google and came to know about the sessions settings save path and all, I am not sure what exactly I need to do here to resolve this.
Remember both projects/applications should exist on the same server
By default codeignitor follows the COOKIE's as a session so you have to ovwerwrite that library with any of the PHP native session libraries.
Then pass the session_id to that project through CRUL or POST or URL in a two way encrypted format. Don't forget to encrypt the session id
From Project 1 :
//to get the session id
$id = session_id();
//do some custom encryption
$id = 'ajhkdhfasjdhfajsdfhkjadf';
**Ref:**
http://www.php.net/manual/en/function.mcrypt-encrypt.php
From Project 2:
Ref:
http://www.php.net/manual/en/function.mcrypt-decrypt.php
The initialize the session id before start the session like below
//do some custom encryption
$id = $this->input->get('id');
//decrypt the value
session_id($id);
session_start();
Now you can access the session values.
when I print the session name in my first application and in one of
new codeignitor code page,, I can see both the sessions are different.
I think this is the problem because codeignitor manages its session.
You are correct about CI handling its own sessions, the way around this issue is to use the native session library.
https://github.com/EllisLab/CodeIgniter/wiki/Native-session
The other way is to make CI use database sessions and just pass the session ID to your new application so you can select the correct data from the database.

Convert Wordpress session to user id

I am working on a WordPress plugin and I have a problem where I get the WordPress logged-in users id & session and i need to create a comment on this user's behalf from my server.
[Update] What I mean by "my server" is from my own Java server. My comment system creates the comments on the Java server and the Java server needs also to create the same comment on the wordpress PHP server. In order to create the comment on the user account i am sending the session to the Java server so it will as the wordpress to convert the session to the user, so it will be secure.
[/update]
The problem is that in order to make this operation secure i need to check with WordPress that the session i got is valid and matches the user id.
I couldn't find any API that convert the session into the user id in order to check that it matches.
anyway to do that with WordPress API?
There are a number of ways you can get the user id from the auth cookie, depending on the path you want to take this are the functions you should check:
get_current_user_id ->Returns the ID of the current user.
wp_get_current_user ->Retrieve the current user object (WP_User).
Wrapper of get_currentuserinfo() using the global variable $current_user. You can check the code of this function here to have an ideea how you can build your script.
wp_validate_auth_cookie -Validates authentication cookie. It returns the user id.
I'm thinking you'll have to use the last one like it is used in get_currentuserinfo:
$user = wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' )
if ($user != 0) { //then we have a valid user...}

login to two websites at the same time in PHP

how do I use the same web session that was created in one web app to another web app? In order words, if I login to site1.php, how do I automatically get logged in (without having to fill a form or anything) to site2.php using the same credentials that I used to login on site1.php?
Any help please
Your users propably get a cookie with their session id set If not, do so. Both sides would have to use the same session backend to be able to get the session for the given id (from cookie). To share sessions between websites both sites need to use the same session handler. For example in a database.
http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/

Categories