473,320 Members | 2,054 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,320 software developers and data experts.

Login / Password

FP
I want to put some code at the top of my pages which will prompt the
user for a name & password if the session variable IDUser is not set.

How do I get the browser to display the login / password dialog and how
do I access the data the user entered.

Can I put the code that gets the login / password in a page of it's own
and have the browser call that page when the IDUser isn't set, and if
so how do I do it eg.
<?
session_start();
If($_SESSION['IDUser']==''){
//how do I tell it to do the authentication page
}else{
//rest of my code
} ?>
Once the user entered a login / password and I set the IDUser on the
authentication page, how do I tell it to resume loading the original
page (the one that had the above mentioned code on it)?

Jul 17 '06 #1
7 2153
Rik
FP wrote:
I want to put some code at the top of my pages which will prompt the
user for a name & password if the session variable IDUser is not set.

How do I get the browser to display the login / password dialog and
how do I access the data the user entered.
http://www.php.net/manual/en/features.http-auth.php

Grtz,
--
Rik Wasmus
Jul 17 '06 #2
Look into header("Location: foo.php");

Go to the login page if not set. Upon success, go to this page.

Shelly
"FP" <ad@pottnerconsulting.cawrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>I want to put some code at the top of my pages which will prompt the
user for a name & password if the session variable IDUser is not set.

How do I get the browser to display the login / password dialog and how
do I access the data the user entered.

Can I put the code that gets the login / password in a page of it's own
and have the browser call that page when the IDUser isn't set, and if
so how do I do it eg.
<?
session_start();
If($_SESSION['IDUser']==''){
//how do I tell it to do the authentication page
}else{
//rest of my code
} ?>
Once the user entered a login / password and I set the IDUser on the
authentication page, how do I tell it to resume loading the original
page (the one that had the above mentioned code on it)?

Jul 17 '06 #3
I've always done somthing like this:

At the begining of your secure scripts
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Start the sesion
session_start();

// Check for login
if(!isset($_SESSION["IDUser"])){
$page = urlencode($_SERVER["REQUEST_URI"]);
exit("<script>window.location.href='login.php?page =$page</script>");
}

// Secured code goes here
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
On your login.php page
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Code used to authenticate

// On authentication, go to passed page
exit("<script>window.location.href='".$_GET["post"]."'</script>");
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

HTH

Sheldon Glickler wrote:
Look into header("Location: foo.php");

Go to the login page if not set. Upon success, go to this page.

Shelly
"FP" <ad@pottnerconsulting.cawrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
I want to put some code at the top of my pages which will prompt the
user for a name & password if the session variable IDUser is not set.

How do I get the browser to display the login / password dialog and how
do I access the data the user entered.

Can I put the code that gets the login / password in a page of it's own
and have the browser call that page when the IDUser isn't set, and if
so how do I do it eg.
<?
session_start();
If($_SESSION['IDUser']==''){
//how do I tell it to do the authentication page
}else{
//rest of my code
} ?>
Once the user entered a login / password and I set the IDUser on the
authentication page, how do I tell it to resume loading the original
page (the one that had the above mentioned code on it)?
Jul 18 '06 #4
FP
Rik wrote:
FP wrote:
I want to put some code at the top of my pages which will prompt the
user for a name & password if the session variable IDUser is not set.

How do I get the browser to display the login / password dialog and
how do I access the data the user entered.

http://www.php.net/manual/en/features.http-auth.php

Grtz,
--
Rik Wasmus

I had a look at the manual and it's clear as mud.
Tomorrow I'm going to try to put the following code in an include and
call it from the different pages; it's currently working with 1 page.
If anyone sees potential problems with it, could you please point them
out.

if ($_SESSION['IDUser']=='') {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Demo"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
//connect to database searching for record where
Login = $_SERVER['PHP_AUTH_USER'];
Pwd = $_SERVER['PHP_AUTH_PW'];
if(no records found){
header('WWW-Authenticate: Basic realm="Demo"');
header('HTTP/1.0 401 Unauthorized');
}else{
$_SESSION['IDUser'] = database record ID
}
}

Jul 18 '06 #5
Message-ID: <11**********************@m79g2000cwm.googlegroups .comfrom
cl*******@gmail.com contained the following:
exit("<script>window.location.href='login.php?page =$page</script>");
Fine but why rely on Javascript? Why not just do:

header("Location:login.php?page=$page");
exit();

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 18 '06 #6

Geoff Berrow wrote:
Message-ID: <11**********************@m79g2000cwm.googlegroups .comfrom
cl*******@gmail.com contained the following:
exit("<script>window.location.href='login.php?page =$page</script>");

Fine but why rely on Javascript? Why not just do:

header("Location:login.php?page=$page");
exit();

Exactly what I was about to post, but Geoff beat me to it :)

header("Location:login.php?page=$page");
will work no matter what Javascript settings the user has, while:

exit("<script>window.location.href='login.php?page =$page</script>");
relies on the visitor's browser understanding javascript (not such a
big problem these days) and on them allowing JavaScript redirects
(which can still be a problem)

Jul 18 '06 #7
Good point. Thank you

william.clarke wrote:
Geoff Berrow wrote:
Message-ID: <11**********************@m79g2000cwm.googlegroups .comfrom
cl*******@gmail.com contained the following:
exit("<script>window.location.href='login.php?page =$page</script>");
Fine but why rely on Javascript? Why not just do:

header("Location:login.php?page=$page");
exit();


Exactly what I was about to post, but Geoff beat me to it :)

header("Location:login.php?page=$page");
will work no matter what Javascript settings the user has, while:

exit("<script>window.location.href='login.php?page =$page</script>");
relies on the visitor's browser understanding javascript (not such a
big problem these days) and on them allowing JavaScript redirects
(which can still be a problem)
Jul 19 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Davis | last post by:
I put a little login (username and password textfields) in a web page, and once the user able to login, I want the username and password textfields will disappear, and replace with text " has...
6
by: josephrthomas | last post by:
hi..i am trying to make a login page and i am using access table.. when the user enters his userid and password i want to check the password from the table.. if any user with the userID that is...
1
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to...
2
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
4
tolkienarda
by: tolkienarda | last post by:
Hi all I work for a small webdesign company and we have remote hosting. i built a mysql database with phpmyadmin on the server. i then downloaded and modified a php login page. i am continuing to...
9
by: Ben | last post by:
Hello, I'll bet this has been asked a million times but I can't seem to find a thread that gives the clear example I need. This PC has MySQL and IIS configured and running. The MySQL database is...
3
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
13
by: Apostle | last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
1
by: punk86 | last post by:
Hi, i can register and login without fail. However i notice that my inputs are not record into the database. I do not know the reason. Can someone guide me into login and register. Actually im...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.