views:

121

answers:

1

I have having difficulties on this one page login.php becuase of the nature of the session it does not allow a $page to be called. I included the header the same way I did on all other pages. The code highlighted between the ===== is my header include with $page defined for the < ul > so I can call a different class each page. But it's not working on the login page due to the sessionstart. I can get it to work fine on other pages.

If you have any idea's let me know.

<?php
session_start();


if ($_POST['username']) {



if( strtolower($_POST['code'])!= strtolower($_SESSION['texto'])){

function headertop($page) {

    include('header.php');

}

headertop('login');


echo "<br /><br />SECURITY CODE ERROR... "; 




include('footer.php');

exit();
}
A: 

First thing first, stop validating POST without an isset() function, so it should look something like if (isset($_POST['key']) : etc.

Next, i suppose You're defining that function in each file ?

You screwed up the definition of it by defining the include to include('header.php'); and not the $page. Then why are U sending the $page parameter at all ? You call it then from header.php ? That's some lame code.

Anyway, what you need to do is a switch or many if-else-if-s in your code, based on the $_SERVER['QUERY_STRING'] or $_SERVER['REQUEST_URI'].

switch ( $_SERVER['PHP_SELF'] ) {
default:
case '/index.php': 
 $tab = 'homenav';    
 break;

case '/surf.php': 
 $tab = 'surfnav';    
 break;

case '/register.php': 
 $tab = 'registernav';     
 break;

}

Kemo
I'm not sure what you mean, if I take header.php out of the include than it wont print my header. The function is what is suppose to call the $page and each page is defined in the CSS
AskaGamer
It's lame to call variables you define in this file from header.php, not a really good practice, and I personally haven't seen a code like yours in years.What you need is to define some rules in something like config.php, based on $_SERVER variables, not some $page variable based on cookie value. Look at my code, I'll edit it in few seconds.
Kemo
I tried adding that to config and didnt work. What would I be doing wrong to the current code?
AskaGamer