See who is on the same page in CodeIgniter - php

I am using CodeIgniter and I connect to a remote database. Only people who are in the table "users" are allowed to log in through session. Some of the tables in the DB can be edited on the site and a form sends the info to the Model (which then updates the info to the DB), what I want to do is the site to tell you who is on the edit page aswell like "John Doe is already editing this table". Is it possible to achieve it with session or something else?
Thankfull for any response.

You can get the current URI with this method (be sure to load the URI helper):
$this->uri->uri_string();
Then I would keep a users table, since they're required to log in, you should already have this, then also keep a field which indicates whether they are logged in or not, then a nullable field indicating which page they are on. Then when you're on an admin/edit page, you can query all users which page = {admin/edit page}, and display which users are on this page.
Let me know if you have any other questions.

Related

What kind of plugin should I use to make a whole page for one user only?

I try to make a website with multiple users of the same role on Wordpress. That may be "Informational system of hotel rooms". Every user should have an access to login page and the page for registration. But after the process of logging in the user should get own private page. In this page the subscriber should get the opportunity to review and edit the database table. But there's no exception of the fact that despite the whole list of database tables is the same by own quantity and structure of each of them, the data stored in those tables should be unique.
The uniqueness of data witnesses that I need to create a private page for every user, save for administrator. It must be private page, not post, because I'll use php snippet and html code for displaying the table with unique data.
So the question is: What kind of plugin should I use to make a whole page for one user only?

Create a page that shows a user which pages they have been to using PHP

I was wondering if there was a way to create a page on my website that would allow for a user to view the pages in the website that they have been to. I have searched around to see if I could find a hint to where I could start from, but I came up empty. I have already coded a system where a user can sign up and log in, I just need a way so that they can track where they have been. Thanks
I won't go into full detail, as I cannot comment to ask how you would prefer, but an example using sessions would be such;
At the start of each page, you could do something as follows;
session_start();
array_push($_SESSION['pages'], "`You would put a user-friendly page name here`");
Or alternatively;
session_start();
array_push($_SESSION['pages'], __FILE__);
The above would store each page the user visits in a session named pages. If you wanted to, for say, receive the last five visited pages, you could then do something as such;
array_slice($_SESSION['pages'], -5);
Although this wouldn't be the most efficient and/or is just basic, it is the bedrock in which you could expand upon.
Another idea would be to log the page visits to a database. You could have a table names page_views or similar with id, user identifier and page as the columns, then following the above example to 'log' the page views to the database. You could then select from the database and limit to the last 5 records matching the user identifier, therefor receiving the five latest logged pages.

select users who currently view same page

I find several partial solutions in answers on this question, but common answer seems to be absent.
So, I have a table users with columns user_id, user_name. On each static page of website I want to display all user names of users who currently view this page.
Should I have a table views with columns user_id, webpage_link?
If yes, when I shall update data in column webpage_link? How to connect code from following answer with mysql database Is there a way to detect if a browser window is not currently active? ? (If it is ok for this purpose.)
To make updates very often is not very good. So, the user can view several pages (for example, in 2 or more tabs). What type of webpage_link column shall be in this case?
With every http request, you get a $path variable. if you also have a logged in user, you can store which page this user requested last (e.g. in a table like you described, but only storing the relative path).
You update this information on a per-request-basis in some sort of front-controller. (just make sure you put it where it is called for every authenticated page). When the users session times out, you remove the row of that user from the table.
this case is a little more difficult. you could store the last n pages/paths the user has requested and leave the rest as above. You don't have to change the table structure for that, just allow for multiple rows per user. (the combination user_id+path should be unique, though)
Hope that helps to get you started

Passing value to Joomla Module from another URL

I'm newbie to Joomla module development, and would like to implement a custom module for Joomla CMS.
I need to display the sales history of the logged in user. For example, a user with [username] = "US001" logged in successfully, and go to view what sales orders have done by him. And the module display the data recordset in table format by passing the "US001" as username parameter to my database and retrieve the data.
How do I detect the user logged in and then remember the [username] for the whole session?
How can I pass this [username] parameter, e.g. "US001" to my external URL for retrieving data record set? My database for every user's sales history is in another different IP's server.
After query the data, how to return back my dataset to the module and draw my table out on that module?
Additional function would be Admin's user able to control which field to be display, eg. 'age', 'e-mail', etc on the table in module.
You want to access the user object. Joomla already has most of what you need built in, you just pull up the current user and you have the info.
To start with, you will need to get the current user info -
`$user =& JFactory::getUser();`
if ($user->guest) will tell you if the user is logged in, $user->name will give you the username
You will have to pass any info from Joomla to the external URL using either GET or POST. Easiest way is to pass it as part of the URL query string (GET) external.url.com/database-page.html?username=name; ?> or similar
Again, GET or POST the values you want to use back to the page containing your module.
Not sure what you mean here, but it sounds like you need to add parameters (called form fields in 1.6 and newer) to your module so you can turn on or off the display of some of the data the module will be getting.
User object tutorial - http://docs.joomla.org/Accessing_the_current_user_object
Parameters - http://docs.joomla.org/Standard_parameter_types
Form fields - http://docs.joomla.org/Form_field
Lastly, it sounds like you would be better served creating a component instead of a module, unless you plan to display the database info you are pulling as part of another page that will be displaying the main content.

Validating Login / Changing User settings / Php Mysql

my questions are about login, and changing already saved data.
Question 1
Until now I've only saved input in the tables of the database (registration steps), now I need to check if the input (login steps), match what is in database. In fact I have 3 types of users, then I'll have to check 3 kind of tables. Then if the input data matches with one of those 3 tables I will redirect the user to their specific area.
I'm thinking about saving the submitted data $login=$_REQUEST['login']; and $password=$_REQUEST['password']; and compare with the login column in the database. Then if the login matches, I'll compare the password submitted with the one in the row, not in the column. But I don't know how to do this search and comparison, neither what to use. Then if both matches I'll redirect the user. Else I'll send a login error message; I know how to do this already.
Question 2
What if I need to change an already saved user, for example if they change their email address? My changing user's data web page is exactly the same like the registration user web page. Can I load the already saved options and values of registration? Then the user will change whatever is necessary, and then when they submit the new information, they would not create a new row in my table, but just overwrite the old information? How can I do this?
Check this out.
Then if that doesn't help a bit, take a look at this.

Categories