darksniperx Posted November 25, 2007 Share Posted November 25, 2007 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. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 Try echoing out echo $_GET['page']; at top of your page. I think it is blank so your code moves to header( 'Location: index.php?page=unlogged' ); Quote Link to comment Share on other sites More sharing options...
darksniperx Posted November 25, 2007 Author Share Posted November 25, 2007 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' ); Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 You keep this at top of your code <?php ob_start(); session_start(); ?> This will remove that Warning, but read here why you got that error http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
darksniperx Posted November 25, 2007 Author Share Posted November 25, 2007 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 Quote Link to comment Share on other sites More sharing options...
darksniperx Posted November 25, 2007 Author Share Posted November 25, 2007 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. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 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' ); } } ?> Quote Link to comment Share on other sites More sharing options...
darksniperx Posted November 25, 2007 Author Share Posted November 25, 2007 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. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 keep this in all pages where you have used session_start and try <?php session_start(); ob_start(); ?> Quote Link to comment Share on other sites More sharing options...
darksniperx Posted November 25, 2007 Author Share Posted November 25, 2007 tryed, still does the same thing. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 Just try replacing header( 'Location: index.php?page=unlogged' ); TO echo "<script>location.href='index.php?page=unlogged'</script>"; Quote Link to comment Share on other sites More sharing options...
darksniperx Posted November 25, 2007 Author Share Posted November 25, 2007 the page started to refresh non stop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.