probelm with sessions and form

This is a discussion on probelm with sessions and form within the PHP Language forums, part of the PHP Programming Forums category; I am not what I am doing wrong. When I enter the log-in info and press submit, I keep ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-19-2004
danarz@gmail.com
 
Posts: n/a
Default 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";

?>

Reply With Quote
  #2 (permalink)  
Old 12-19-2004
badr
 
Posts: n/a
Default Re: probelm with sessions and form

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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:40 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0