473,748 Members | 10,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble with login script

tolkienarda
316 Contributor
hi all i have a login script that is simplified with out any extra stuff. and it doesn't seem to work. i think the problem is something to do with session variables. but i am not sure what it is. below are the scripts in their entirety along with a description of all outputs

first page - login.htm
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>login</title>
  4. </head>
  5. <body>
  6. <form action="login.php" method="post">
  7. Username: <input type="text" name="uname"><br>
  8. Password: <input type="text" name="pass"><br>
  9. <input type="submit">
  10. </form>
  11. </body>
  12. </html>
  13.  
this is prety self explanitory
i get a username and password from the user
then sends it into the login.php script

[PHP]
<?
$uname = $_POST['uname'];
$pass = $_POST['pass'];
if ($uname == 'dreimer' && $pass == 'id10t')
{
session_start() ;
$_SESSION['logged'] = 'yes';
//echo $_SESSION[['logged'];
header("locatio n: logged.php");
}
?>
[/PHP]
now this gets the uname and the pass from post and checks then against the username and password that i have preset. i can get into this if statement fine. i then set a session variable ['logged'] and that is equal to 'yes'. then i redirect the header to logged.php. when i un comment the line that prints the session variable the browser displays 'yes'

and the final page
[PHP]
<?
session_start() ;
if ($_SESSION['logged'] != 'yes');
{
echo 'ahah';
//echo $_SESSION['logged'] ;
//header("locatio n: login.htm");
}
?>
<head>
<title>Untitl ed Document</title>
</head>
<body>
logged in sucessfully
</body>
</html>
[/PHP]

of here i check to see if the session variable isn't yes. and the browse displays 'ahah' and when i un comment the printing of the session variable i get the same output so basicaly i can read session vars off the page where they are set but not off other pages.

i have worked on this problem for several weeks and tried using cookies to solve the problem as well but nothing seems to work

if anyone can help me please help

eric
Apr 12 '07 #1
8 2144
exoskeleton
104 New Member
hi sir... i also tried that one and it wont work...try to place session_start() above all codes...

[PHP]
session_start() ;

$uname = $_POST['uname'];
$pass = $_POST['pass'];
if ($uname == 'dreimer' && $pass == 'id10t')
{

$_SESSION['logged'] = 'yes';
//echo $_SESSION[['logged'];
header("locatio n: logged.php");
}[/PHP]

hope this helps...more power
Apr 13 '07 #2
manirajmurali
2 New Member
<?
session_start() ;
if (!isset($_SESSI ON['logged'] = 'yes'))
{
echo 'ahah';
//echo $_SESSION['logged'] ;
//header("locatio n: login.htm");
}
?>
<head>
<title>Untitl ed Document</title>
</head>
<body>
logged in sucessfully
</body>
</html>
Apr 13 '07 #3
tolkienarda
316 Contributor
thanks exoskelton that seemed to fix my problem.


eric
Apr 13 '07 #4
tolkienarda
316 Contributor
ok so one more small problem below is where i check to make sure i have logged in successfully

[PHP]
<?
session_start() ;
$log = $_SESSION['logged'];
if ($log != 'yes');
{
echo $log;
//header("locatio n: login.htm");
}
?>
[/PHP]

the screen shows yes as being the value for $log so am i totaly confused cause i thought != meant not equal to but maybe i am wrong. if anyone sees the problem here please help

thanks a million

eric
Apr 13 '07 #5
exoskeleton
104 New Member
im glad it helped... " != " means not equal to. your right! but you said it still echos yes?

try this:

[PHP]if(isset($_sess ion['logged']) {

echo "You are logged in";

} else {

echo "You are not logged in";

}[/PHP]
Apr 14 '07 #6
exoskeleton
104 New Member
im glad it helped... " != " means not equal to. your right! but you said it still echos yes?

try this:

[PHP]if(isset($_sess ion['logged']) {

echo "You are logged in";

} else {

echo "You are not logged in";

}[/PHP]
sorry....lack of ")" hehe

heres the right one:

[PHP]if(isset($_sess ion['logged'])) {

echo "You are logged in";

} else {

echo "You are not logged in";

}[/PHP]

i think your code have just a little problem, it is just the ";" in your if statement.

[PHP]if(xxxxxxxxxxxx xxxx) ; <------ over here
{

echo "xxxxxxxxxxxxx" ;

} [/PHP]
Apr 14 '07 #7
tolkienarda
316 Contributor
oh dear it appears that my stupidty is boundless i have been programing for three years in various languages you would think i would have learned where ';' go.

thanks and sorry it took so long for me to respond my hard disk crashed. ahah

eric
Apr 17 '07 #8
exoskeleton
104 New Member
oh dear it appears that my stupidty is boundless i have been programing for three years in various languages you would think i would have learned where ';' go.

thanks and sorry it took so long for me to respond my hard disk crashed. ahah

eric
hehe chill sir.. no problem ... :D
Apr 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2879
by: koolyio | last post by:
Hey, could you please tell me what is wrong with my login script. I just started learning php. CODE: login.php <? session_start(); header("Cache-Control: private"); ?>
6
1913
by: Daniel Walzenbach | last post by:
Hi, I have an application using "Forms authentication". Everything works perfectly well except when I try to open a new page with java script like the following: <script language='javascript'>window.open (myPage.aspx','','Fullscreen=no; Scrollbars=yes; Menubar=no; Locationbar=no; Resizable=yes; Status=no;') </script>
1
6433
by: pj | last post by:
I'm trying to redirect users to another page after they Authenticate with the ASP.NET login controls. The user is able to login, but I can't get the response.redirect to work. Can anyone help? My code is below. Thanks, pj mcdba, mcp
0
2393
by: kang jia | last post by:
hi i am currently learning Django framework and i have to do a login page at the moment. i have used the code like following: from django.contrib.auth import authenticate, login def my_view(request): username = request.POST password = request.POST
14
8631
victorduwon
by: victorduwon | last post by:
Hi guys and gals, I am using javascript to autologin to my google analytics account via a hyperlink. This is what the text looks like this <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3
6223
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it has to tell then them its wrong information but currently it takes then to a next page and then tells them its incorrect information. This is tedious as every time they enter wrong they will be redirected to a different page and then they have to...
2
2450
by: gradinafrica | last post by:
I'm trying to create a log out button that uses AJAX to call a php file which ends the current session: //logout.php <?php if (!session_start()); session_destroy(); //Destroys the session echo "success"; ?>
9
7531
by: adweaver | last post by:
Hello All, I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs. The site was built in a folder called mysite.com/test. I coppied this folder a number of times, so I now have mysite.com/test2, mysite.com/test3 etc. Each folder acts as its own landing page. they setup an interface where we can control the upsells presented to the customer;...
21
3867
by: tvnaidu | last post by:
This is the Java script I am using fo rlogin page, but cursor not pointing to login box, any idea how can I point cursor to login box when this page loaded?. here admin login take to control page and user login take to status page, if I give direct path without goto login, both pages display, can I add a check if user didn't login, then redirect to login page for both control.htm and status.htm, let me know. thanks in advance. <script...
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.