473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Session Registration with Username?

I'm using this script to ensure users are logged in to view the page.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. if(!session_is_registered(username)){
  4. header("location:client.htm");
  5. }
  6. ?>
It works fine but is there any way I can restrict this to just one (or pultiple) username(s)?

EDIT - Also, is it possible to restrict the access/content of a certain folder to particular users?
Nov 28 '08 #1
3 1690
Markus
6,050 Expert 4TB
@alfandango
2. I'll answer, or try to answer, your second question first. If you're looking to restrict a folder, you'd want to look into using .htaccess files, I think. There may be a better way.

1. The session_register() and functions like it rely on register_globals() to be enabled. Don't use them; stick to the $_SESSION array.

You can check the contents of the session by $_SESSION['username'] and then compare it to a list of allowed usernames - this usually comes from a database.

Thanks,
Markus.
Nov 28 '08 #2
Not sure I fully understand (sorry I'm new to PHP so may be a little slow off the mark)...

Do you mean something like this?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $_SESSION['username'] = $username;
  4.  
  5. if (!$username==admin)
  6.     {
  7.         header("location:client.htm");
  8.     }
  9. ?>
It may bad code, but it restrics access to the page, but also to the user "admin" which is supposed to be the only one WITH access :(

Essentially what I'm trying to do is:
1) load page
2) check logged in user
3) if "admin" allow access to page
4) if not "admin" redirect back to client.htm

Regarding the other point, I'll look into htaccess.

Cheers dude!
Nov 28 '08 #3
Markus
6,050 Expert 4TB
@alfandango
Yeh, you've got the jist of it.

But admin should be in quotes -> "admin".

Let's have a look at your log in page, to see if there's a problem there. (Use [code] tags).
Nov 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
6
by: Ruben van Engelenburg | last post by:
Hi all, I have a strange problem. I have a login procedure that uses a mysql database in which the users are stored. The login procedure is pretty straightforward. In every page I unclude my...
1
by: karolina | last post by:
Hi, I have a homepage where it is possible to register as a user. The registration takes place in three steps. The first step is user data and in the end it sets session variables to username...
14
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you...
2
by: Todd | last post by:
Here's one that has been stumping people: I'm writing in ASPX with VB.NET On the login page I set the entered usename text to a session variable....
2
by: samcode3 | last post by:
Hi, I would be thankfull if anyone could give me the solution for this header problem. There are no blank spaces at end as there is html code in end. I have used <?php session_start();?> in first...
2
by: Ned Balzer | last post by:
Hi, Apologies if this is a newbie question, I haven't found the answer in any faqs. I have an asp.net 2.0 page that sets session variables and then redirects to another page. For the page...
1
by: Tarcetial | last post by:
Im trying to make a personal website with a log in/registration system. I found some help with the log in and now i just need some help with the registration. This is the coding im already using: ...
7
by: gowthamkg | last post by:
For the following code when ever i open the this page the text box has / i ahve set the value of text box with session variables whic is exuted only when submit button is clicked....Pls Help me.......
9
by: happyse27 | last post by:
Hi All, In perl script(item b below) where we check if html registration form are filled in properly without blank with the necessary fields, how to prompt users that the field are incomplete...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.