473,391 Members | 1,484 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,391 software developers and data experts.

Login Scripting

Hi All

Definitely a newbie with PHP, though I have messed with it a bit. I could
use some guidance here as I have spent the better part of 3 days walking the
net looking for an example.

Trying to accomplish:

When the user goes to the main page, index.html, they can enter a
username/password combo to go beyond. When the login button is pressed, the
script, login.php, is run to validate their entry and then send them along
to the first secure page, welcome.php. At the same time, if they just type
welcome.php in the address line, I would like them to be bounced back to the
index.html screen to do the login thing.

I've tried the header function, but keep getting errors about headers
already being sent. Research on this has led me to the session_register and
session_cache_limiter, but my main problem is that the header function seems
to be able to be used only once in the particular session. If I shut down
IE and start it up again, things work.

Any help out there or any reference links that may help to clear up my
misunderstanding?

Thanks.

Brad
Jul 17 '05 #1
6 1806
I noticed that Message-ID: <L9yjd.144164$Pl.30993@pd7tw1no> from Brad
Farrell contained the following:
I've tried the header function, but keep getting errors about headers
already being sent. Research on this has led me to the session_register and
session_cache_limiter, but my main problem is that the header function seems
to be able to be used only once in the particular session. If I shut down
IE and start it up again, things work.


At the beginning of each page to be sent to a login page

<?php
session_start();
if($_SESSION['logged_in']==""){
header("Location: login.php");
exit;
}

Login.php
(This code is fine for one or two discrete username password
combinations. For more, you will be better off using a database)

<?php
session_start();
$_SESSION['logged_in']="";
$userpass=array("user1-pass1","user2-pass2","usern-passn");
$input=strtolower($_POST['username'])."-".strtolower($_POST['password']);

if(in_array($input,$userpass)){
$_SESSION['logged_in']=1;
}

then some data entry, error messages and so on

--
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 17 '05 #2
.oO(Geoff Berrow)
header("Location: login.php");


The Location-header requires an absolute URL.

Micha
Jul 17 '05 #3
Thanks. That did the trick. I think I had some other issues with the
header function, but it now seems to be working just fine.

Brad
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:e7********************************@4ax.com...
I noticed that Message-ID: <L9yjd.144164$Pl.30993@pd7tw1no> from Brad
Farrell contained the following:
I've tried the header function, but keep getting errors about headers
already being sent. Research on this has led me to the session_register andsession_cache_limiter, but my main problem is that the header function seemsto be able to be used only once in the particular session. If I shut downIE and start it up again, things work.


At the beginning of each page to be sent to a login page

<?php
session_start();
if($_SESSION['logged_in']==""){
header("Location: login.php");
exit;
}

Login.php
(This code is fine for one or two discrete username password
combinations. For more, you will be better off using a database)

<?php
session_start();
$_SESSION['logged_in']="";
$userpass=array("user1-pass1","user2-pass2","usern-passn");
$input=strtolower($_POST['username'])."-".strtolower($_POST['password']);

if(in_array($input,$userpass)){
$_SESSION['logged_in']=1;
}

then some data entry, error messages and so on

--
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 17 '05 #4
I noticed that Message-ID: <bc********************************@4ax.com>
from Michael Fesser contained the following:
.oO(Geoff Berrow)
header("Location: login.php");


The Location-header requires an absolute URL.


It's always worked for me. What clients do not accept this?
--
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 17 '05 #5
The error message means that before you issue header('location: login.php');
you have already written something out. Look for any previous echo or print
statements, or even a blank line somewhere.

--
Tony Marston

http://www.tonymarston.net

"Brad Farrell" <br**********@brevell.com> wrote in message
news:L9yjd.144164$Pl.30993@pd7tw1no...
Hi All

Definitely a newbie with PHP, though I have messed with it a bit. I could
use some guidance here as I have spent the better part of 3 days walking
the
net looking for an example.

Trying to accomplish:

When the user goes to the main page, index.html, they can enter a
username/password combo to go beyond. When the login button is pressed,
the
script, login.php, is run to validate their entry and then send them along
to the first secure page, welcome.php. At the same time, if they just
type
welcome.php in the address line, I would like them to be bounced back to
the
index.html screen to do the login thing.

I've tried the header function, but keep getting errors about headers
already being sent. Research on this has led me to the session_register
and
session_cache_limiter, but my main problem is that the header function
seems
to be able to be used only once in the particular session. If I shut down
IE and start it up again, things work.

Any help out there or any reference links that may help to clear up my
misunderstanding?

Thanks.

Brad

Jul 17 '05 #6
.oO(Geoff Berrow)
I noticed that Message-ID: <bc********************************@4ax.com>
from Michael Fesser contained the following:
The Location-header requires an absolute URL.


It's always worked for me. What clients do not accept this?


Doesn't matter, the full URL is required by the HTTP specification.

Micha
Jul 17 '05 #7

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

Similar topics

11
by: Ghazan Haider | last post by:
I am posting this for the lack of a better newsgroup, and for the knowledge of people here, and because its only partially OT. We have a bunch of users with their computers at work. There are...
5
by: Phillip Armitage | last post by:
I've spent the better part of two days checking out PHP, javascript and numerous other language sites trying to find what I figure should be be an easy web script page. Essentially what I want is a...
1
by: cgian31 | last post by:
I need to hide the complexity from users to access an information webpage, which is normally accessible after filling in a web form with the correct data. The address of the information webpage...
2
by: Pete Lux | last post by:
I have built a web form that displays data, but I've hard coded the username/password/database. I can create a separate .aspx for that info, but I'd like to find out how to navigate back and forth....
4
by: sowencheung | last post by:
Hi, all The scenario is like this: I have a master page, contains two user controls, one is a search control, another is a login control. The server-side <form> is in the master page,...
0
by: mracuraintegra | last post by:
I'm stuck on a pretty big problem, and can't seem to find a solution, so any help would be greatly appreciated! I'm working with the default page generated for remote desktop web clients (in the...
3
by: JDS | last post by:
So, I'd like to create the following scenario: 1) Use cURL library within PHP (cURL + "Cookie Jar", et.al) to create a virtual browser session that "logs in" to a remote site. (For example: ...
10
by: Mel | last post by:
I am using "windows" authentication mode. I would like to store the username and various information when the user logs on to the website. Any ideas? It would be a bonus to store the logout...
2
neo008
by: neo008 | last post by:
Hi all, I want to make a website where user can enter and see contents only by using given user ID and Password. Can somebody suggest me what technology should I adopt for best and easy way....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.