can't display username in redirect page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nilupa
Forum Newbie
Posts: 4
Joined: Wed Jun 27, 2007 6:02 am

can't display username in redirect page

Post by nilupa »

i cannot display logged user name's in the redirect page( index_grant.php). i think this is a session problem according my little knowledge. can anyone give me a solution for this. [s]pls[/s] please.

here are [s]da[/s] the codes

index.php

in this page get username & password and pass it to 1.php

Code: Select all

<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 
include("config.php");
echo "<form method='post' action='1.php'><table border='0' width='80%' id='table4'>";
echo "<tr><td><strong>Username</strong></td><td width='50%'><input type='username' style='width:97px; height:18px; font-family:tahoma; font-size:11px ' name='username' size='20'></td></tr>";
echo "<tr><td><strong>Password</strong></td><td><input type='password' style='width:97px; height:18px; font-family:tahoma; font-size:11px ' name='password' size='20' ><input name='go' type='image' src='images/go.jpg' align='top' style='margin-left:7px'</td></tr>";
 
echo "</table></form>";
 
?>

in 1.php

in this check the user and redirected to index_grant.php

Code: Select all

<?php
include("config.php");
 
 
/*$callback="index_grant.php?err=#error#";
$callback .= "$name=".urlencode($_REQUEST["username"]);*/
$_user_name = $_POST['username'];
$_password = $_POST['password'];
 
//check the login
mysql_connect($host, $user_name, $password)
   or die('Could not connect: ' . mysql_error());
 
//select database
mysql_select_db($database_name) or die('Could not select database');
$result = mysql_query("SELECT * FROM users WHERE username='$_user_name'") or die(mysql_error());  
$row = mysql_fetch_array( $result );
if($row['username'] == '')
{
echo "<b>&nbsp;&nbsp;&nbsp;Username or Password is incorrect.&nbsp;<a href='index.php' class='red'> [Go Back]</a></b>";//<br>";
}
else
{
if($row['password'] == $_password)
{
$_SESSION['logged'] = "agk8gjf38834j2";
$_SESSION['user'] = $_user_name;
$name=$row['username'];
//echo($name);
 
 
header("location:" . 'index_grant.php');
//header("1.php");
}
else
{
echo "<b>&nbsp;&nbsp;&nbsp;Username or Password is incorrect.&nbsp;<a href='index.php' class='red'> [Go Back]</a></b>";//<br>";
}
//session_destroy();
 
}
?>




in index_grant.php

logout & display username

Code: Select all

<?php
include("config.php");
 
   
//echo($_REQUEST[$seuser]);
 
 
$_SESSION['user'];
$username=$_SESSION['user'];
//echo ;
 /*?>if($_SESSION['logged'] != 'agk8gjf38834j2')
{
header("location:" . $_login_file);
} */
   
   
 echo "<div style='margin-top:20px'><div style='margin-left:10px'><b> Welcome, You are Logged in|  <a href='logout.php' class='red'>log out [ administrator$username ]</a></b></div></div>";
//session_destroy();
?>



if need any clarification [s]pls[/s] please post.

[s]tnx[/s] thanks

nilupa. :?
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

where do you call session_start()?
nilupa
Forum Newbie
Posts: 4
Joined: Wed Jun 27, 2007 6:02 am

Post by nilupa »

or i forgot that :

config.php

call in all the php files.( your can see)

Code: Select all

<?php
//READ 'README.TXT' FIRST
//config file
ob_start();
session_start();
//mysql info
$host = "localhost";         //mysql host
$user_name = "admin";             //mysql username
$password = "itpdr3";              //mysql password
$database_name = "region3";         //mysql database name
//$_login_file = "index.php";  //login page
//$redirect_url = "index_grant.php";  //main page;where it is redirected after login
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, please try

Code: Select all

session_write_close();
header('location: index_grant.php');
nilupa
Forum Newbie
Posts: 4
Joined: Wed Jun 27, 2007 6:02 am

Post by nilupa »

in where ? in index_grant.php or some where else.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

How many calls to header/location (that are not commented) are there in your code?
Post Reply