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

I have a wrong idea on how to code...Welcome, mankolele

The " Welcome, mankolele. "part on each site how is it coded I thought it has something to do with COOKIES or SESSIONS but seems I am wrong anyone who could help me with this bit.

Thanks in advance.
Jan 17 '07 #1
14 1814
ronverdonk
4,258 Expert 4TB
The welcome message itself has nothing to do with cookies or sessions. It is only displayed after you logged in and merely mirrors the name (userid) you have entered yourself. When you want to use that userid in more places during a session, you can store it in a cookie or session.

So: after you entered your userid and password, these values are POSTed to a script that goes something like:[php]
$user = $_POST['user'];
$psw = $_POST['psw''];
//
// verify validity of userid and password
//
// if valid:
echo "Welcome $user";
//
// else:
echo "You entered an invalid userid and/or password";
exit;[/php]
Ronald :cool:
Jan 17 '07 #2
The welcome message itself has nothing to do with cookies or sessions. It is only displayed after you logged in and merely mirrors the name (userid) you have entered yourself. When you want to use that userid in more places during a session, you can store it in a cookie or session.

So: after you entered your userid and password, these values are POSTed to a script that goes something like:[php]
$user = $_POST['user'];
$psw = $_POST['psw''];
//
// verify validity of userid and password
//
// if valid:
echo "Welcome $user";
//
// else:
echo "You entered an invalid userid and/or password";
exit;[/php]
Ronald :cool:
Thanks for the quick reply, but I am still lost I have a LOG-IN page when the user is logged-in they get to their page that is where they will be welcomed. or maybe its me who leaves something out.The Welcome still comes out alone without the name.
Jan 17 '07 #3
ronverdonk
4,258 Expert 4TB
Only way to resolve this is that you post the code here. Within code or php tags PLEASE.

Ronald :cool:
Jan 17 '07 #4
the login

[PHP]

$connection = mysql_connect("localhost", "root", "issasql");
$select_db = mysql_select_db("schools", $connection);
$connection = mysql_connect("localhost", "root", "issasql");
$select_db = mysql_select_db("schools", $connection);
$query = mysql_query ("SELECT username,password,id FROM passdb where id ='".$_SESSION["id"]."'", $connection);

if(isset($_COOKIE['ID_my_site'])){


$name = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT password,username,id FROM passdb WHERE id = '".$_POST['username']."'")or die(mysql_error());
//$check = mysql_query("SELECT cust_username,cust_pswrd FROM customer WHERE cust_username = '$cust_username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
} else {
header("Location: admin_home.html");
//header("Location: welcome.php");
}
}
}

if (isset($_POST['submit'])) {
if(!$_POST['username'] || !$_POST['password']) {
//die('You did not fill in a required field.<a href=index.html>back</a>');
header("Location: loginFail2.html");
//die('href=loginFail.html');
}

//if (!get_magic_quotes_gpc()) {
// $_POST['email'] = ($_POST['email']);
// $_POST['email'] = addslashes($_POST['email']);
//}

$check = mysql_query("SELECT password,username, status FROM passdb WHERE username = '".$_POST['username']."'")or die(mysql_error());

//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
header("Location: loginFail3.html");
//die('That user does not exist in our database. <a href=index.html>Click Here to Register</a>');
} else {

while(list( $password,$username, $status) = mysql_fetch_array( $check ))
{
$_POST['password'] =($_POST['password']);
$password = ($password);
$_POST['password'] = ($_POST['password']);

if ($_POST['password']!= $password) {
header("Location: loginFail.html");
//die('Incorrect password, please try again.<a href=index.html>Click Here </a>');
} else {

if ($status == 'T'){

$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
//header("Location: viewProduct.html");
header("Location: attendance_t.php");

} else if ($status == 'L') {


$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
//header("Location: search_user.php");
//header("Location: viewSupp.php");
header("Location: ViewLearnerInfo.php");

}
else if ($status == 'A') {


$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
header("Location: reg.html");

}
}
}
//}
}}


[/PHP]

The page to where the learner goes to

[PHP]

$server = 'localhost';
$username = 'root';
$password = 'issasql';
$database = 'schools';

// (1) Connect to the MySQL server
$connection = @ mysql_connect($server, $username, $password)OR die("Error ".mysql_errno()." : ".mysql_error());
// (2) Select the database
$select_db = mysql_select_db($database, $connection) OR die("Error ".mysql_errno()." : ".mysql_error());

$sql = mysql_query("select * from passdb where id = '".$_SESSION["id"]."'") or die(mysql_error()) ;


[/PHP]

[HTML]<html>
<head>
<title>Student front page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="file:///D|/Faxregister/docroot/styles" rel="stylesheet" type="text/css">
</head>

<body>
<form action="" method="post" name="Form">
<table width="100%" border="0">
<tr>
<td><img src="faxBanner.png" width="968" height="115"></td>
</tr>
</table>
<table width="100%" border="1" align="right" bordercolor="#FF9900" bgcolor="#999999">
<tr>
<th width="18%" bordercolor="#FFFFCC" bgcolor="#FF9900"><div align="center"><strong>Student
Home</strong></div></th>
<td width="82%" bordercolor="#FFFF00"><div align="center">
<table width="808" border="1" align="center" bordercolor="#000000">
<tr>
<td width=100%> <div align="center"></div>
<div align="center"><a href="attend_report_initial.html">Attendance
Report</a> | <a href="viewAssignment.html">Assignment</a> | Books
| Class Test Schedule | Exam Schedule | Fees | <a href="publicH.html">Holidays</a>
| <a href="viewHomework_initial.html">Home Work</a> | Report |
<a href="viewTimetable.html">TimeTable </a></div></td>
</tr>
</table> </td>
</tr>
</table>
<br></br>
<br>
<hr align="center" color="#000000">
[PHP]
$username = $_POST['username'];
$password = $_POST['password'];


echo "Welcome ".$username;
//if(isset($_COOKIE['lastVisit']))
//$visit = $_COOKIE['lastVisit'];
//else
// echo "You've got some stale cookies!";

//echo "Your last visit was - ". $visit;
[/PHP] <p align="center"><strong><em>Notice Board</em></strong></p>
<div align="center">
<table width="47%" height="260" border="4" bordercolor="#FF9900">
<tr>
<td bordercolor="#FF9900" bgcolor="#FFFFFF"><div align="center">

</div>
</td>
</tr>
</table>
<br></br>
</div>

</form>
<!--
<SCRIPT LANGUAGE='JavaScript'>
<!--

var default1 = "Online School Management System : MANAGE SCHOOL ACTIVITIES"; // only shown once at page load
var text1 = "Online School Management System : LEARNER MANAGEMENT";
var text2 = "Online School Management System : CLASS MANAGEMENT";
var text3 = "Online School Management System : TEACHER MANAGEMENT";
var changeRate = 2000; // 1000 = 1 second
var messageNumber = 0;

function changeStatus() {
if (messageNumber == 0) {
document.title=default1;

}
else if (messageNumber == 1) {
document.title=text1;
}
else if (messageNumber == 2) {
document.title=text2;
}
else if (messageNumber == 3) {
document.title=text3;
messageNumber = 0;
}

messageNumber++;
setTimeout("changeStatus();",changeRate);

}

changeStatus(); // leave here to run right away

// -->
</SCRIPT>
<script language="JavaScript" type ="text/javascript">

function alertViewSelected(){

if(document.Form.select.value == ""){
alert("Please select a Criteria for searching");
document.Form.select.focus();
return false;
}

if(document.Form.textfield.value == ""){
alert("Please enter the Subject you wish to search");
document.Form.text.focus();
return false;
}
}

</script>
</body>
</html>[/HTML]
Jan 17 '07 #5
ronverdonk
4,258 Expert 4TB
I have no idea how you pass the userid around. Certainly NOT via the $_POST array. And I cannot see in your code where you POST the userid.

I can see that you do
Expand|Select|Wrap|Line Numbers
  1. $_POST['userid'] = stripslashes($_POST['userid']);
  2. header('Location: something.php');
but that way (the GET method) the $_POST array is NOT PASSED to something.php, because there is no POST array.

Ronald :cool:
Jan 17 '07 #6
I have no idea how you pass the userid around. Certainly NOT via the $_POST array. And I cannot see in your code where you POST the userid.

I can see that you do
Expand|Select|Wrap|Line Numbers
  1. $_POST['userid'] = stripslashes($_POST['userid']);
  2. header('Location: something.php');
but that way (the GET method) the $_POST array is NOT PASSED to something.php, because there is no POST array.

Ronald :cool:
Thanks for the reply, still I dont get what I have to do I changed to passing the id but still works the same.
Jan 18 '07 #7
Thanks for the reply, still I dont get what I have to do I changed to passing the id but still works the same.
Ok this may sound dump to some people but I really dont get how to do it please help.
Jan 19 '07 #8
Atli
5,058 Expert 4TB
Hi there.

This code is much to complex for what you are trying to do, it looks like it was made by 5 ppl trying to do the same thing each in their own way :)

I see you use $_Post to send the user information, but you try to verify them using $_Cookie. And somwhere in the middle of this you try to use $_Session to retriev a userid I cant see that you set anywhere.

I for one try to avoid $_Cookie as much as I can... its just.. messy :)

I would do this something like this.

[PHP]
if(isset($_POST['loginsubmit']))
{
$DB = @mysql_connect("host", "user", "pass") or die("Die!!");
@mysql_select_db("dbofDOOM", $DB);

$QUERY = "SELECT UserID FROM table WHERE UserName = ' {$_POST['UserName']}' AND Password = sha('{$_POST['Password']}')";
$RESULT = @mysql_query($QUERY);

if(!!$RESULT)
{
if(mysql_num_rows($RESULT) != 0)
{
echo "Welcome ". $_POST['UserName'];

$row = @mysql_fetch_assoc($RESULT);
$_SESSION['UserID'] = $row['UserID'];
}
else
{
echo "User info wrong!!";
}
}
else
{
echo "The page you are viewing is broken. Please go yell at the administrator.";
}
}
else
{
echo "<form action\"\" method=\"post\">
User: <input type=\"text\" name=\"UserName\" />
<br>Pass: <input type=\"password\" name=\"Password\" />
<br><input type=\"submit\" name=\"loginsubmit\" />
</form>";
}[/PHP]

And now you have your the user id in the $_Session array so you can call it anywhere you like.

Hope this helps :)
Jan 19 '07 #9
Hi there.

This code is much to complex for what you are trying to do, it looks like it was made by 5 ppl trying to do the same thing each in their own way :)

I see you use $_Post to send the user information, but you try to verify them using $_Cookie. And somwhere in the middle of this you try to use $_Session to retriev a userid I cant see that you set anywhere.

I for one try to avoid $_Cookie as much as I can... its just.. messy :)

I would do this something like this.

[PHP]
if(isset($_POST['loginsubmit']))
{
$DB = @mysql_connect("host", "user", "pass") or die("Die!!");
@mysql_select_db("dbofDOOM", $DB);

$QUERY = "SELECT UserID FROM table WHERE UserName = ' {$_POST['UserName']}' AND Password = sha('{$_POST['Password']}')";
$RESULT = @mysql_query($QUERY);

if(!!$RESULT)
{
if(mysql_num_rows($RESULT) != 0)
{
echo "Welcome ". $_POST['UserName'];

$row = @mysql_fetch_assoc($RESULT);
$_SESSION['UserID'] = $row['UserID'];
}
else
{
echo "User info wrong!!";
}
}
else
{
echo "The page you are viewing is broken. Please go yell at the administrator.";
}
}
else
{
echo "<form action\"\" method=\"post\">
User: <input type=\"text\" name=\"UserName\" />
<br>Pass: <input type=\"password\" name=\"Password\" />
<br><input type=\"submit\" name=\"loginsubmit\" />
</form>";
}[/PHP]

And now you have your the user id in the $_Session array so you can call it anywhere you like.

Hope this helps :)
Thanks for the reply but I only get to the page is broken cant get through. I admit I am new to PHP and trying not to make it obvious. What amm I missing here?

Thanx
Jan 19 '07 #10
Atli
5,058 Expert 4TB
The database info is most likely wrong, I'd bet you forgot to change the table name in the $QUERY

I already tested the code and it works fine if the info is right ;)
Jan 19 '07 #11
The database info is most likely wrong, I'd bet you forgot to change the table name in the $QUERY

I already tested the code and it works fine if the info is right ;)

That was the first thing I changed, the id is auoto_increment is my primary key where the username ,password and the rest follows..... this is making me feel really stupid coz its been 4days working on it and it is a small thing I know, but what?
Jan 19 '07 #12
Atli
5,058 Expert 4TB
We know the script works... so it is the mysql data that is wrong.
So we need the page to print the database error when it accures.

Add this where the "Page is broken" is printed
[PHP]echo "<br>". $QUERY;
echo "<br>". mysql_error();
[/PHP]

Now when you run the script, if the query fails you should be able to see they query and the error returned by mysql.

O and I just noticed.. In the query I sha() encoded the password... it migth be the problem. Try removing it
Jan 19 '07 #13
We know the script works... so it is the mysql data that is wrong.
So we need the page to print the database error when it accures.

Add this where the "Page is broken" is printed
[PHP]echo "<br>". $QUERY;
echo "<br>". mysql_error();
[/PHP]

Now when you run the script, if the query fails you should be able to see they query and the error returned by mysql.

O and I just noticed.. In the query I sha() encoded the password... it migth be the problem. Try removing it
Thanks it works I removed more than just the sha().Thanks for the patience again.
Jan 22 '07 #14
Oh no! the login page pops up twice, from the original one it goes to the right page with another login form, when removing the second one it does not display the welcome note , I think I dont have the right logic, I know I dont any idea how to fix that?

Thankx
Jan 23 '07 #15

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

Similar topics

4
by: R.Meijer | last post by:
Hi, I've been busy with an experimental script, and I can't seem to see what is wrong with it, can somebody tell me? Here it is: a = 0 b = 1 mainloop = 1 print "Welcome to pyFibo"
1
by: learningGuy | last post by:
Can someone tell me what is wrong with this simple code? I get an exception every time at the myFile.Open() line. I have included the code that I think is needed to for you to answer this below:...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
1
by: alex | last post by:
Hello I have some c++ code, which has been happily developped in the linux/unix world. Everything has always been compiled with different compiler (intel, KAI, g++...) and gnu makefiles For...
60
by: Dominique Léger | last post by:
Hello guys, I'm kinda new to C, and I'm having a hard time with strings. What I'm trying to do is a simple function that trims spaces & tabs at the beginning of a given string. For example, I...
1
by: Matthew Wilson | last post by:
I need to write a function crc(msg, len) that gets a char array of length len and then calculates the crc32 for the code. I don't understand what's going wrong in the code I have. It goes...
1
by: Holly | last post by:
One of my clients called me this morning, having trouble with their blog loading. The blog does actually load, but only after such an unusually long wait it would have surely driven everyone else...
7
by: =?Utf-8?B?TWF4R3J1dmVu?= | last post by:
I have a DLL that implements the Business and Data Layers for a number of different websites. That DLL uses a Strongly Typed DataSet to interface to the Data Source which is SQL Server. There...
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...
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...
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
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...
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.