Hello everyone.. I have a quick question. I am trying to change the header location depending on the session vars. i have a index.php that includes a class that has the user login function. but when I try to change the header it says there's a problem with changing the header. I have went over it and over it for white spaces, and empty lines.. you can look at the source. I know its open but its okay.
Thanks for you help.
www.xfxdesigns.com
http://www.xfxdesigns.com/tempaltes/template.login.php
http://www.xfxdesigns.com/classes/class.corefuns.php
header with sessions. need some help please
Moderator: General Moderators
Re: header with sessions. need some help please
I can't access the two URL's in your post and without the actual error I can't help much.
Make sure that there is absolutely nothing outputted before the header() function is called.
Make sure that there is absolutely nothing outputted before the header() function is called.
Re: header with sessions. need some help please
Thank you. Here is the code for the index.php
<?php
$page = $_GET['p'];
if(isset($_SESSION['username']))
{
header("location: http://google.com");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.3org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" href="templates/main/css/layout.css" type="text/css">
</head>
<body>
<div id='wrapper'>
<div id='headerwr'>
</div>
<div id='topnavwr'>
<div id="tnButtonHolder">
<span class='TopNavLinks'>
<a href='#' style='margin-right: 4px;'>Home</a>
<a href='#' style='margin-right: 4px;'>Products</a>
<a href='#' style='margin-right: 4px;'>Web Hosting</a>
<a href='' style='margin-right: 4px;'>Web Design</a>
<a href='?p=login' style='margin-right: 4px;'>User Login</a>
</span>
</div>
</div>
<div id="centerbackground">
<div id='leftwr'>
<?php
include_once('templates/main/template.left.php');
?>
</div>
<div id='middlewr'>
<?php
if (($page == "index") or ($page ==""))
{
include('templates/main/template.main.php');
}
else if($page == "products")
{
include('templates/main/template.products.php');
}
else if($page == "webdesign")
{
include('templates/main/template.webdesign.php');
}
else if($page == "login")
{
include('templates/main/template.login.php');
}
else if($page == "admin")
{
include('admin/templates/admin.template.adminpanel.php');
}
else if(($page == 'addblock1' or $page == 'addblock2'))
{
include('admin/templates/admin.template.addblock.php');
}
else if($page == "viewblocks")
{
include('admin/templates/admin.template.viewblocks.php');
}
else if($page == "checklogin")
{
include_once('classes/class.corefuncs.php');
$obj = new class_corefuncs();
$obj->userlogin();
}
else
{
echo 'Wrong Page';
}
?>
</div>
</div>
<br />
</div>
<div id='footerwr'>
<span>this is the footer</span>
</div>
</body>
</html>
and here is the corefuncs.php
<?php
include_once('class.mysqlfuncs.php');
class class_corefuncs
{
public function getSideBoxes()
{
$obj = new class_mysqlfuncs();
$sqlConn = $obj->sqlConnect();
$return = $obj->sqlQuery("SELECT * FROM sideboxes");
return $return;
}
public function getContentBoxes()
{
$obj = new class_mysqlfuncs();
$sqlConn = $obj->sqlConnect();
$return = $obj->sqlQuery("SELECT * FROM contentboxes order by orderid ASC LIMIT 10");
return $return;
}
public function userLogin()
{
$obj = new class_mysqlfuncs();
$sqlConn = $obj->sqlConnect();
$strUser = $_POST['username'];
$strPass = $_POST['password'];
$strUser = stripslashes($strUser);
$strPass = stripslashes($strPass);
$strUser = mysql_real_escape_string($strUser);
$strPass = mysql_real_escape_string($strPass);
$strReturn = $obj->sqlQuery("SELECT username, password FROM siteusers WHERE siteusers.username=\"{$strUser}\" and siteusers.password=\"{$strPass}\"");
$x=mysql_num_rows($strReturn);
if($x == 1)
{
session_start();
$_SESSION['username']=$strUser;
}
else
{
echo "wrong username or password";
}
}
}
?>
and the template.login.php
<div id='loginwr'>
<div id='headermiddle'># User Login</div>
<div id='conmiddle'>
<form id='login' method='post' action='?p=checklogin'>
<input type='text' name='username'></input><br>
<input type='text' name='password'></input>
<input type='submit' value='login' name='submit'></input>
</form>
</div>
</div>
is this what ya need?
<?php
$page = $_GET['p'];
if(isset($_SESSION['username']))
{
header("location: http://google.com");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.3org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" href="templates/main/css/layout.css" type="text/css">
</head>
<body>
<div id='wrapper'>
<div id='headerwr'>
</div>
<div id='topnavwr'>
<div id="tnButtonHolder">
<span class='TopNavLinks'>
<a href='#' style='margin-right: 4px;'>Home</a>
<a href='#' style='margin-right: 4px;'>Products</a>
<a href='#' style='margin-right: 4px;'>Web Hosting</a>
<a href='' style='margin-right: 4px;'>Web Design</a>
<a href='?p=login' style='margin-right: 4px;'>User Login</a>
</span>
</div>
</div>
<div id="centerbackground">
<div id='leftwr'>
<?php
include_once('templates/main/template.left.php');
?>
</div>
<div id='middlewr'>
<?php
if (($page == "index") or ($page ==""))
{
include('templates/main/template.main.php');
}
else if($page == "products")
{
include('templates/main/template.products.php');
}
else if($page == "webdesign")
{
include('templates/main/template.webdesign.php');
}
else if($page == "login")
{
include('templates/main/template.login.php');
}
else if($page == "admin")
{
include('admin/templates/admin.template.adminpanel.php');
}
else if(($page == 'addblock1' or $page == 'addblock2'))
{
include('admin/templates/admin.template.addblock.php');
}
else if($page == "viewblocks")
{
include('admin/templates/admin.template.viewblocks.php');
}
else if($page == "checklogin")
{
include_once('classes/class.corefuncs.php');
$obj = new class_corefuncs();
$obj->userlogin();
}
else
{
echo 'Wrong Page';
}
?>
</div>
</div>
<br />
</div>
<div id='footerwr'>
<span>this is the footer</span>
</div>
</body>
</html>
and here is the corefuncs.php
<?php
include_once('class.mysqlfuncs.php');
class class_corefuncs
{
public function getSideBoxes()
{
$obj = new class_mysqlfuncs();
$sqlConn = $obj->sqlConnect();
$return = $obj->sqlQuery("SELECT * FROM sideboxes");
return $return;
}
public function getContentBoxes()
{
$obj = new class_mysqlfuncs();
$sqlConn = $obj->sqlConnect();
$return = $obj->sqlQuery("SELECT * FROM contentboxes order by orderid ASC LIMIT 10");
return $return;
}
public function userLogin()
{
$obj = new class_mysqlfuncs();
$sqlConn = $obj->sqlConnect();
$strUser = $_POST['username'];
$strPass = $_POST['password'];
$strUser = stripslashes($strUser);
$strPass = stripslashes($strPass);
$strUser = mysql_real_escape_string($strUser);
$strPass = mysql_real_escape_string($strPass);
$strReturn = $obj->sqlQuery("SELECT username, password FROM siteusers WHERE siteusers.username=\"{$strUser}\" and siteusers.password=\"{$strPass}\"");
$x=mysql_num_rows($strReturn);
if($x == 1)
{
session_start();
$_SESSION['username']=$strUser;
}
else
{
echo "wrong username or password";
}
}
}
?>
and the template.login.php
<div id='loginwr'>
<div id='headermiddle'># User Login</div>
<div id='conmiddle'>
<form id='login' method='post' action='?p=checklogin'>
<input type='text' name='username'></input><br>
<input type='text' name='password'></input>
<input type='submit' value='login' name='submit'></input>
</form>
</div>
</div>
is this what ya need?
Re: header with sessions. need some help please
With the code you provided I was unable to reproduce an error... Could you copy/paste the error so we know exactly what it is? Are there any files included before index.php?
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: header with sessions. need some help please
Don't you need
before the call to $_SESSION['username']? Unless the script knows to resume the session, it won't find any session variables.
Code: Select all
session_start()-
dhenick
- Forum Newbie
- Posts: 19
- Joined: Tue Oct 20, 2009 10:46 am
- Location: Yogyakarta, Indonesia
- Contact:
Re: header with sessions. need some help please
or may be you can Cleaning the output buffering before header call.
you can add
at the top of your page.
I hope it's can be help.
you can add
Code: Select all
ob_start();
I hope it's can be help.