Jump to content

nested if loop error, need help


darksniperx

Recommended Posts

session_start();
include_once 'forms.php';
if($_GET['page']== null)
{
header( 'Location: index.php?page=main_page' ) ;
}
else if (file_exists(getcwd() .'/forms/' . $_GET['page'] . '.php'))
{/*do nothing*/}
else{header( 'Location: index.php?page=404' );}
//everything went ok, up to here 
//as soon as I added the code below I started to get problems
if ((isset($_SESSION['user_logged']) && $_SESSION['user_logged'] != "") || 
(isset($_SESSION['user_password']) && $_SESSION['user_password'] != "")) 
{ //Do Nothing!}
else
{
$index_page = strcmp($_GET['page'], "main_page");
$page_notfound = strcmp($_GET['page'], "404");
if($index_page == 0 || $page_notfound == 0)
{ //Do Nothing!}
else
{
	header( 'Location: index.php?page=unlogged' );
}
}

the code checks at first is the url that was give is correct, if not it is set to default page

then the code checks if the url leads to an existent page or not, if the page does not exits, the code redirects to page 404

 

the part where I am started to get problems on is when I have checked if the user has been logged in or not. if logged in, do nothing if not logged in, then check if the user wants to go to main_page or page 404, if he is then do nothing, otherwise redirect to page where user needs to log in.

 

the part that I have mentioned that checks for user sessions and so on, always tries to go to page call unlogged and then display the page cannot be found on the server, when the file is there. if I take out the buggy code then everything works and it can find all of the pages. how would I go about fixing the buggy code, there is just some minor logic error.

Link to comment
Share on other sites

I get the following message

Entry
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/alex/alpha3/index.php:27) in /home/frdowd3/public_html/alex/alpha3/index.php on line 28

line 28 is ->

header( 'Location: index.php?page=unlogged' );

Link to comment
Share on other sites

my guess that i had to clear header buffer.

 

I have added the line,  and still get dns error

 

I have reread the link that you have sent me, and buffering header files still doesnt help me, it did not show the error message that I got with echo, but the problem php pointing out dns errors is still there, and on the same line: header( 'Location: index.php?page=unlogged' );s

Link to comment
Share on other sites

at the moment right now, I cant even view the error , because as soon as the code gets to header( 'Location: index.php?page=unlogged' );

 

I get page cannot be found, dns, error, and echo does not help anymore. if I comment out header( 'Location: index.php?page=unlogged' ); then I can view unlogged page.

 

sorry for double post, could not edit the previous one.

Link to comment
Share on other sites

Try echoing out every part, it will be easy to find which part is not working properly, I have added some echo, try this

<?php
ob_start();
session_start();
include_once 'forms.php';
if($_GET['page']=="")
{
header( 'Location: index.php?page=main_page' ) ;
}
elseif (file_exists(getcwd() .'/forms/' . $_GET['page'] . '.php'))
{
echo "Check for file exists succeded";
}
else{
header( 'Location: index.php?page=404' );
}
//everything went ok, up to here 
//as soon as I added the code below I started to get problems
if ((isset($_SESSION['user_logged']) && $_SESSION['user_logged'] != "")) 
{ 
echo "User is logged in.";
}
else
{
$index_page = strcmp($_GET['page'], "main_page");
$page_notfound = strcmp($_GET['page'], "404");
echo $index_page."<br />";
echo $page_notfound."<br />";

if($index_page == 0 || $page_notfound == 0)
{ 
echo "Index page or page not found matches";
}
else
{
	echo "Need to redirect to Unlogged page";
	//header( 'Location: index.php?page=unlogged' );
}
}
?>

Link to comment
Share on other sites

when I runned main_page-> index.php?page=main_page

Check for file exists succeded0
1
Index page or page not found matches

 

when I funned with Feed

Check for file exists succeded-1
1
Need to redirect to Unlogged page

 

it seems that the code is working, going to the right direction, untill it reaches header.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.