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

using Sessions for the first time

Hi all.
I dont know if there is some configurations which has to be done to be able to use sessions coz I have the iusername and password for a person to log in from the database and now edited it to use sessions says wrong entry.Then trying to register new member also it does not go to the database.Am I missing something here.

Thanx in advance
Nov 15 '06 #1
5 1690
Hi all.
I dont know if there is some configurations which has to be done to be able to use sessions coz I have the iusername and password for a person to log in from the database and now edited it to use sessions says wrong entry.Then trying to register new member also it does not go to the database.Am I missing something here.

Thanx in advance
try this, maybe it will anwser some of your questions:
[PHP]
<?php
session_start();
if (!isset($_SESSION['user']))
{
$Username = "user"; // let suppose it comes from a form or a database ;-)
$Password = "12345";
$_SESSION['user'] = $Username;
$_SESSION['pass'] = $Password;
echo "you are not logged in";
}
else
echo "hi ".$_SESSION['user'].", welcome back<br>";

?>
<html>
<body>
<a href="<?=$_SERVER['PHP_SELF']?>">Click here to log</a>
</body>
</html>
[/PHP]
Nov 15 '06 #2
try this, maybe it will anwser some of your questions:
[PHP]
<?php
session_start();
if (!isset($_SESSION['user']))
{
$Username = "user"; // let suppose it comes from a form or a database ;-)
$Password = "12345";
$_SESSION['user'] = $Username;
$_SESSION['pass'] = $Password;
echo "you are not logged in";
}
else
echo "hi ".$_SESSION['user'].", welcome back<br>";

?>
<html>
<body>
<a href="<?=$_SERVER['PHP_SELF']?>">Click here to log</a>
</body>
</html>
[/PHP]
Thanks for replying but when I put the conncetion to the database it takes the databases username not the ones I have in my database. Is there something I am doing wrong or what.
Nov 16 '06 #3
Thanks for replying but when I put the conncetion to the database it takes the databases username not the ones I have in my database. Is there something I am doing wrong or what.
would you kindly show your script ..
Nov 16 '06 #4
/////This is my form it always goes to Wrong login no matter what
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>login form</title>

<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<table><tr><td>
<img src="asset.png">
</td></tr></table>
<form action='loginck.php' method=post>
<table border='0' cellspacing='0' cellpadding='0' align=center>
<tr id='cat'>
<tr> <td bgcolor='#f1f1f1' ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;Login ID &nbsp; &nbsp;
</font></td> <td bgcolor='#f1f1f1' align='center'><font face='verdana, arial, helvetica' size='2' >
<input type ='text' class='bginput' name='username' ></font></td></tr>

<tr> <td bgcolor='#ffffff' ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;Password
</font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' >
<input type ='text' class='bginput' name='password' ></font></td></tr>

<tr>
<td bgcolor='#f1f1f1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
<input name="submit" type='submit' value='Submit'>
<input type='reset' value='Reset'>
</font></td>
</tr>


<tr> <td bgcolor='#ffffff' ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;<a href='signup.php'>New Member Sign UP</a></font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' ><a href=forgot-password.php>
Forgot Password</a> ?</font></td></tr>

<tr> <td bgcolor='#f1f1f1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
&nbsp;</font></td> </tr>


</table></center></form>


</body>

</html>


////the validation is done here

<?

include "session.php";

include "z_db.php";
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<table><tr><td>
<img src="asset.png">
</td></tr></table>
<?
$username=mysql_real_escape_string($username);
$password=mysql_real_escape_string($password);

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$username' AND password = '$password'"))){
if(($rec['username']==$username)&&($rec['password']==$password)){
include "newsession.php";
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
print "<script>";
print " self.location='welcome.php';"; // Comment this line if you don't want to redirect
print "</script>";

}
}
else {

session_unset();
echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";

}
?>

</body>

</html>

Oh I also have two sessions a SESSION and NEW SESSION not sure what is the difference between the two.Maybe what I am doing wrong is here not sure

SESSION.PHP

<?php
session_start();
session_register("session");
?>


NEWSESSION.PHP

<?php

//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
$session['id']=session_id();
$session['username']=$username;
//echo $session['userid'];
?>
Nov 17 '06 #5
Oh I also have two sessions a SESSION and NEW SESSION not sure what is the difference between the two.Maybe what I am doing wrong is here not sure

SESSION.PHP

[php]
session_start();
session_register("session");
[/php]


NEWSESSION.PHP

[php]

//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
$session['id']=session_id();
$session['username']=$username;
//echo $session['userid'];
[/php]
This is my form it always goes to Wrong login no matter what.Did not have the tags before now I put them in.
<!doctype html public "-//w3c//dtd html 3.2//en">

[html]

<head>
<title>login form</title>

<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<table><tr><td>
<img src="asset.png">
</td></tr></table>
<form action='loginck.php' method=post>
<table border='0' cellspacing='0' cellpadding='0' align=center>
<tr id='cat'>
<tr> <td bgcolor='#f1f1f1' ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;Login ID &nbsp; &nbsp;
</font></td> <td bgcolor='#f1f1f1' align='center'><font face='verdana, arial, helvetica' size='2' >
<input type ='text' class='bginput' name='username' ></font></td></tr>

<tr> <td bgcolor='#ffffff' ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;Password
</font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' >
<input type ='text' class='bginput' name='password' ></font></td></tr>

<tr>
<td bgcolor='#f1f1f1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
<input name="submit" type='submit' value='Submit'>
<input type='reset' value='Reset'>
</font></td>
</tr>


<tr> <td bgcolor='#ffffff' ><font face='verdana, arial, helvetica' size='2' align='center'> &nbsp;<a href='signup.php'>New Member Sign UP</a></font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' ><a href=forgot-password.php>
Forgot Password</a> ?</font></td></tr>

<tr> <td bgcolor='#f1f1f1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
&nbsp;</font></td> </tr>


</table></center></form>


</body>

[/html]


////the validation is done here

[php]

include "session.php";

include "z_db.php";
//////////////////////////////
[/php]
<!doctype html public "-//w3c//dtd html 3.2//en">

[html]

<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<table><tr><td>
<img src="asset.png">
</td></tr></table>
<?
$username=mysql_real_escape_string($username);
$password=mysql_real_escape_string($password);

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$username' AND password = '$password'"))){
if(($rec['username']==$username)&&($rec['password']==$password)){
include "newsession.php";
echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
print "<script>";
print " self.location='welcome.php';"; // Comment this line if you don't want to redirect
print "</script>";

}
}
else {

session_unset();
echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";

}
[/php]

</body>

[/html]
Nov 23 '06 #6

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

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...
0
by: Gleep | last post by:
Hey PHP Gurus, I have some complex scripts that work fine. I have a system where sessions are validated on every page of my application to keep them secure. Everything runs fine when I test and...
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';...
19
by: Jeff Clark | last post by:
Hiya! How would i get this number? thanks!
7
by: Earl Teigrob | last post by:
The first time any of my web apps are hit, they take a long time (45 seconds) for the JIT compiler to compile them. After being hit the first time, they are very fast. My boss is starting to think...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
9
by: AndersBj | last post by:
Hi all, I have a web application that uses State Server for session handling. The web application randomly loses all session variables. The sessions are not always lost, sometimes I can use the...
3
by: Dave Smithz | last post by:
Hi there, I have a website where users can log into. This users sessions as I believe most people use when implementing a login section of a website (each php page first checks a valid parameter...
5
by: John Scott | last post by:
Ok..this a rather odd question/problem. I haven't really found a straight forward answer to how to handle this scenario, so I hope someone here can help. Here it is: I have an application...
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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.