473,395 Members | 1,532 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.

probelm with sessions and form

I am not what I am doing wrong. When I enter the log-in info and press
submit, I keep getting the login section repeatedly (I never get
loged-in).
It works fine if I delete the php session lines.
Here is the script:

<?
session_start();
session_register("username");
session_register("password");
session_register("allowed");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>

<?
if ($username != 'user' or $password != 'pass')
{
?>
<form action="self.php" method="post">
<input name="username" type="text" id="username" value="user name">
<input name="password" type="password" id="password" value="password">
<input type="submit" name="Submit" value="Submit">
</form>
<? ;
exit;
}
echo "This section includes the rest of the page that shows up if the
correct log-in info is submitted";

?>

Jul 17 '05 #1
1 1453
hi , dan
of course it will not work fine , but we can fix this
to work with session you have to do some steps i'll list here some
important points and you will make the validation in your server
(check)
----------------------------------------------
1- Are the sessions working ?
-check php.ini file in you system directory usually (C:\windows) you
will find some thing like this
session.save_path = "C:/php/session_directory" so session_directory is
the location where the session are stored on the server
-check session_directory is it there and your script really write the
session there (in session_directory).
---------------------------------------------
2-now let us disscuss how you check these data , you do like this :
-------------------your code------------------
if ($username != 'user' or $password != 'pass')
-------------------your code------------------
you first need to check if the sessions are registered or not by using
session_is_registered() method, to
do so like this :
--------------------------my code---------------------
if (!(session_is_registered("username") &&
session_is_registered("password")))
--------------------------my code---------------------
so (session_is_registered("your_session_var") is the function that give
you ability to check these information......
--------------------------------------------
3-but your code is need more maintinance if you want to get the value
of the sessions you can do somthing like this:
if ($_SESSION['username']!= 'user name' || $_SESSION['username']!=
'pass')
--------------------------------------------
$_SESSION is PHP array that give you the accessability to your session
varaibles
--------------------------------------------
i, hope this will help you and tell me about the result.

Jul 17 '05 #2

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

Similar topics

1
by: Mountain Man | last post by:
Hi, I posted on this matter earlier with the subject line "Trouble with sessions," but someone else started a different thread with the same subject line that arrived before my post, so I'm...
1
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am...
17
by: Peter Chant | last post by:
Am I right in assuming that when I connect from one browser, using several tabs to a database produced in mysql/php/apache only uses one session for all tabs? I have been loosing records from my...
9
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
13
by: G | last post by:
Hello, Is it possible to send form values from PAGE1 to PAGE2, and then retain the form info for PAGE3 without using cookies, sessions or DB storage? Also, I dont want to repost page2 to page3...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
4
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I...
7
by: Steve Wright | last post by:
Forgive my ignorance, but I am just starting to learn about sessions in PHP and how to pass data from one page to the next. What I'm about to explain could just be my misunderstanding of how...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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.