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

simple session login problem

I created a php page that will create a session for a user. My problem
is that once they are logged in, I dont know how to send them to the
secure page. I dont know where to place the following lines of code:
(also not sure where on the server the pages are placed)

header("Location: http://www.mysite.com/index.html");
exit;

Original code-------------------------------------------------
<?
session_start();
?>
<html>
<head>
<title> </title>
</head>
<body>
<?
$_Username = "user";
$_Password = "password";
// If the form was submitted
if ($_POST['Submitted'] == "True") {
// If the username and password match up, then continue...
if ($_POST['Username'] == $_Username && $_POST['Password'] ==
$_Password) {
// Username and password matched, set them as logged in and
set the
// Username to a session variable.
$_SESSION['Logged_In'] = "True";
$_SESSION['Username'] = $_Username;
}
}
if ($_SESSION['Logged_In'] != "True") {
echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] .
"\">
Username: <input type=\"textbox\" name=\"Username\"><br />
Password: <input type=\"textbox\" name=\"Password\"><br />
<input type=\"hidden\" name=\"Submitted\" value=\"True\">
<input type=\"Submit\" name=\"Submit\">
</form>";
}
else
{
echo "You are logged in as: <b>" . $_SESSION['Username'] . "</b>
<br /><a href=\"" . $_SERVER['PHP_SELF'] .
"?mode=logout\">Logout</a>";
}
if ($_GET['mode'] == "logout") {
session_start();
$_SESSION = array();
session_destroy();
echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=" .
$_SERVER['PHP_SELF'] . "\">";
}
?>
<p>&nbsp;</p>
</body>
</html>
Jul 17 '05 #1
3 2196
On 16 Oct 2004 12:42:34 -0700, em******@hotmail.com (Frank) wrote:
I created a php page that will create a session for a user. My problem
is that once they are logged in, I dont know how to send them to the
secure page. I dont know where to place the following lines of code:
(also not sure where on the server the pages are placed)

header("Location: http://www.mysite.com/index.html");
exit;


Place it right after you create the sessions upon successful user
login. You probably also want to check and verify the form variables
for security.

Anthony
Jul 17 '05 #2
If I place it after a sucessful login, I get ....
Warning: Cannot modify header information - headers already sent by
(output started at /my server path/my site.com/login1.php:9) in /my
server path/my site.com/login1.php on line 41
successful login code...SNIP>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "You are logged in as: <b>" . $_SESSION['Username'] . "</b>
<br /><a href=\"" . $_SERVER['PHP_SELF'] .
"?mode=logout\">Logout</a>";
header("Location: http://www.mysite.com/index.html");
exit;
>>>>>>>>>>>>>>>>>>>>>>>

Anthony <ca*********@gmail.com> wrote in message news:<1097970490.76HQl5mnEbwbH2IbEhxF+w@teranews>. .. On 16 Oct 2004 12:42:34 -0700, em******@hotmail.com (Frank) wrote:
I created a php page that will create a session for a user. My problem
is that once they are logged in, I dont know how to send them to the
secure page. I dont know where to place the following lines of code:
(also not sure where on the server the pages are placed)

header("Location: http://www.mysite.com/index.html");
exit;


Place it right after you create the sessions upon successful user
login. You probably also want to check and verify the form variables
for security.

Anthony

Jul 17 '05 #3
Frank wrote:
If I place it after a sucessful login, I get ....
Warning: Cannot modify header information - headers already sent by
(output started at /my server path/my site.com/login1.php:9) in /my
server path/my site.com/login1.php on line 41
successful login code...SNIP>>>>>>>>>>>>>>>>>>>>>>>>>>
echo "You are logged in as: <b>" . $_SESSION['Username'] . "</b>
<br /><a href=\"" . $_SERVER['PHP_SELF'] .
"?mode=logout\">Logout</a>";
header("Location: http://www.mysite.com/index.html");
exit;


You have to sent headers before the content, and you already echoed the
login name. You can use buffered output (ob_* functions), or maybe
accumulate output in a variable and then echo it at the end (although I
don't see a readon why to output anything if you are redirecting anyway :))
Jul 17 '05 #4

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

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...
3
by: Pavel Vetesnik | last post by:
Greetings! I have some troubles with session variables. I can easily create a session, but the variable I append to global session array ( $_SESSION) lasts only until the end of current...
1
by: Scott Lyon | last post by:
I'm maintaining (read: I didn't write it, nor do I have the time to spend to rewrite it) an application that is suddenly giving me grief. The reason I say suddenly, is because we're in the...
1
by: farooqazeem | last post by:
Hi guys, I’m facing some problem can u solve it. Problem is: I’m giving user Id and password in (Login_sess.asp) and submit it to page (sess_test.asp). I am setting session variable...
11
by: Cecil Westerhof | last post by:
Is it possible to end a session a from another session b, if I know the SessionID from a?
0
by: DotNetShadow | last post by:
Hi Guys I was wondering if you can help me out with the following problem. I created a basic secure | non secure website. So I have the root directory as publically allowable pages and a...
2
by: Tom | last post by:
I hope someone can help me figure out what's going on here. I've re-read the section on sessions at php.net and Googled this high and low but I haven't found anything that quite explains my...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
2
by: jwhite68 | last post by:
The essence of my problem is this. 1. I login to my website with user/password. 2. I select any option, which effectively re-calls index2.php with some additional parameters, to control whats...
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.