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

how to echo out the username of the session.

142 100+
Hi,

I got the page login.php that have a script that logs you in and then go to loggedin.php with a piece of code to validate your loged in.

The validate stores the username, how can I echo the username out onto the page?



Login.php

[PHP]
<?php
session_start();
// dBase file
$con = mysql_connect("www.seeandsee.co.za","seej","jas654 ");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("regsvqs", $con);
if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
{
die("You need to provide a username and password.");
}
// Create query
$q = "SELECT * FROM `details` "
."WHERE `a`='".$_POST["username"]."' "
."AND `b`='".$_POST["password"]."' "
."LIMIT 1";
// Run query
$r = mysql_query($q);
if ( $obj = @mysql_fetch_object($r) )
{

// Login good, create session variables
$_SESSION["valid_id"] = $obj->id;
$_SESSION["valid_user"] = $_POST["username"];
$_SESSION["valid_time"] = time();
// Redirect to member page
Header("Location: /vqs/register/loggedin.php");
}
else
{
// Login not successful
die("Sorry, could not log you in. Wrong login information.");
}
}
else

{?>

<?
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
echo "<br><a href=\"pass.php\">forgot password? </a>";
}
?>
[/PHP]


loggedin.php

[PHP]

<?php
session_start();

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: index.php");
}


?>
[/PHP]
Oct 30 '07 #1
1 5617
webandwe
142 100+
got it.


echo "". $_SESSION['valid_user'];
Oct 30 '07 #2

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

Similar topics

1
by: Nick Whitelegg | last post by:
Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication script which checks a username/password. If the...
3
by: Pavel Vetesnik | last post by:
Greetings! I have some troubles with session variables. I can easily create a session, but the variable I append to global session array ( $_SESSION) lasts only until the end of current...
7
by: deko | last post by:
I have a login page that is supposed to redirect the user to his private page after login. But header("Location: $url") does not work after I set the $_SESSION variable - I get "Warning: Cannot...
2
by: Stefan Mueller | last post by:
If I run the following PHP script the session variable auth_ok changes to true resp. false only if I press the button 1 resp. 2 twice. =================== <?php session_start(); if...
1
by: NurAzije | last post by:
Hi, I keep getting this message can any one help please: Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at...
9
by: bb nicole | last post by:
I want 2 use session in my login, but i never use session before. How to change my code as below if i want to use session... Can somebody give me some opinion, please.. Thanks a lot.. Below is my php...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
2
by: Akhenaten | last post by:
Related to my previous question on searching through an array, I discovered the issue. I have a session variable ($username) which I can not call inside my functions. I can call it just fine...
11
by: craigtomo | last post by:
i have changed my login .php file to the following this file is opened directly and is not called from any other file <?php // dBase file $host=""; // Host name $username=""; // Mysql...
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
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?
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
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,...
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...

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.