Jump to content

help with sessions :(


DataSpy

Recommended Posts

I'm making a new website for my club and I'm using a different technique for navigation.  You know a regular link would be

<a href="link.php">link</a>

 

instead I'm using

<?php
if($_GET['go'] == "" or $_GET['go'] == "home"){
        include("home.php");
    }
elseif($_GET['go'] == "about"){
        include("about.php");
}
elseif($_GET['go'] == "members"){
        include("members.php");
}
elseif($_GET['go'] == "artists"){
        include("artists.php");
}
elseif($_GET['go'] == "links"){
        include("links.php");
}
elseif($_GET['go'] == "login"){
        include("login.php");
}
?>

 

Just thought I would try it out. 

 

The problem is that now when I go to the login page (that use to work) I get the errors

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\xampp\htdocs\xampp\www\shin\index.php:5) in C:\Program Files\xampp\htdocs\xampp\www\shin\login.php on line 2

 

and

 

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\xampp\www\shin\index.php:5) in C:\Program Files\xampp\htdocs\xampp\www\shin\login.php on line 4

 

if I got to 127.0.0.1/club/index.php?go=login I get errors but if I go to 127.0.0.1/club/login.php it works, so I'm a little confused!

 

All the code for the two pages

 

index.php

<?php include ("admin/config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title><? echo "$page_title"; ?></title>
  <link rel="stylesheet" type="text/css" href="css/css.css">
</head>
<body bgcolor="<? echo "$background_color"; ?>" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<table border="0" width="100%" height="100%" cellspacing="0" cellpadding="2">
<!-- header -->
<?php include ("includes/header.php"); ?>
<tr height="1">
<td>
<!-- navigation -->
<?php include ("includes/nav_main.php"); ?>
</td>
</tr>
<!-- display -->
<tr>
    <td>
<?php
if($_GET['go'] == "" or $_GET['go'] == "home"){
        include("home.php");
    }
elseif($_GET['go'] == "about"){
        include("about.php");
}
elseif($_GET['go'] == "members"){
        include("members.php");
}
elseif($_GET['go'] == "artists"){
        include("artists.php");
}
elseif($_GET['go'] == "links"){
        include("links.php");
}
elseif($_GET['go'] == "login"){
        include("login.php");
}
?>
</td>
</tr>
<!-- footer -->
<tr height="1">
<td>
<?php include ("includes/footer.php"); ?>
</td>
</tr>
</table>
</body>
</html>

 

login.php

<?php
session_start();
if(session_is_registered(user)){
header("location:admin/index2.php");
}
?>
<script language="JavaScript">
<!-- begin
function validate(){
user=document.protection.user.value;
if ((user == '')){
    alert('Please fill out Username field');
    return false;
}
pass=document.protection.pass.value;
if ((pass == '')){
    alert('Please fill out Password field');
    return false;
}
else return true;
}
// end -->
</script>
<center><h3>Administration Login</h3></center>
<form action="login_check.php" name="protection" method="post" onSubmit="return validate()"><br>
<table border="0" cellpadding="3" cellspacing="5" align="center" class="hide">
<tr>
<td>
<b>Username:</b>
</td>
<td>
<input type="text" name="user" size="10">
</td>
</tr>
<tr>
<td>
<b>Password:</b>
</td>
<td>
<input type="password" name="pass" size="10">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit"></form>
</td>
</tr>
</table>

 

Any help greatly appretiated, thanx in advance!!!!!!!!

 

I've also read the sticky about sessions and I don't think this pertains to this, but I could be wrong :)

 

Also beside giving me those errors the script actually works but I still get the errors for some reason?

Link to comment
https://forums.phpfreaks.com/topic/41368-help-with-sessions/
Share on other sites

Remove the "session_start()" call from each of the included scripts and move it to the very start of the main script.

 

Also, you can change the "if-elseif" block to  a "switch" statement.

 

Here is the "switch":

<?php
$inc = '';
switch ($_GET['go']) {
    case '':
    case 'home':
        $inc = 'home';
        break;
    case 'about':
    case 'members':
    case 'artists':
    case 'links':
    case 'login':
        $inc = $_GET['go'];
        break;
}
if ($inc != '') include($inc . '.php');
else echo "No such section";
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/41368-help-with-sessions/#findComment-200426
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.