473,326 Members | 2,114 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,326 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 1803
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.