havox Posted November 21, 2010 Share Posted November 21, 2010 I apologize to keep posting this in different topics, but since I can't edit my last topic to fit this one; I must. <?php error_reporting(-1); ini_set('display_errors', 1); function check() { $admin="test"; $pass="test"; if (isset($_POST["user"]) && $_POST["user"] == $admin && isset($_POST["pwd"]) && $_POST["pwd"] == $pass) { sesshin(); } } function sesshin() { session_start(); $_SESSION['user'] = "test"; if ($_SESSION['user'] = "test") { header('Location: output.php'); } else { header('Location: index.html'); } } ?> I get the following errors when I try to login. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /srv/www/deadnode.com/public_html/function.php:25) in /srv/www/deadnode.com/public_html/function.php on line 15 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /srv/www/deadnode.com/public_html/function.php:25) in /srv/www/deadnode.com/public_html/function.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /srv/www/deadnode.com/public_html/function.php:25) in /srv/www/deadnode.com/public_html/function.php on line 1 I've just confused myself into doing this. Maybe I can do all of this in one function? Check(), should look to see if the form information is correct. If so, then it should start the session and proceed to the output.php page. The other thing I'm trying to figure out is how to block public view of output.php if you havent logged in. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 output began on line 25, but i don't get 25 lines of code in your post. is there anything in the file before the code you posted? Quote Link to comment Share on other sites More sharing options...
havox Posted November 21, 2010 Author Share Posted November 21, 2010 That is everything that is function.php, but I did check my index.html file and line 25 is where the code for the button is; that is just a guess though. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 so, is function.php included in an HTML file? Quote Link to comment Share on other sites More sharing options...
havox Posted November 21, 2010 Author Share Posted November 21, 2010 No, but check.php is the action of the form. Which in turn links itself to function.php <?php require('function.php'); check(); ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 is that all of check.php? i suspect that there is some output: a blank space, some html, ANYTHING that occurs before you use session_start(). Quote Link to comment Share on other sites More sharing options...
havox Posted November 21, 2010 Author Share Posted November 21, 2010 Well check.php initiates check() which in turn runs sesshin() where session should be started. When I enter a incorrect password it just stops at check.php and displays no errors. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 the value for error_reporting should be changed to this: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); that shouldn't fix the problem, but -1 isn't a proper value for that. you should also be able to remove this line: ini_set('display_errors', 1); Quote Link to comment Share on other sites More sharing options...
havox Posted November 21, 2010 Author Share Posted November 21, 2010 When I did that it is showing no errors now, but it is stopping at check.php still Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 odd. you'll probably want to put this back in: ini_set('display_errors', 1); Quote Link to comment Share on other sites More sharing options...
havox Posted November 21, 2010 Author Share Posted November 21, 2010 Ok the issue is fixed it goes through all the steps. I'm trying to make a redirect back to index.html if someone try just go ahead and go to one of my pages. I added this to my function.php function blah() { if ($_SESSION['user'] != "test") { redirect('Location: index.html'); } } I get the following error Parse error: syntax error, unexpected $end in /srv/www/deadnode.com/public_html/function.php on line 30 I have no idea if redirect is even real it just highlighted like header did so I figured I would try. Would http_redirect work? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 the syntax error usually indicates a missing right curly bracket } unless you have a function called redirect, use header('Location: index.html'); exit; Quote Link to comment Share on other sites More sharing options...
havox Posted November 21, 2010 Author Share Posted November 21, 2010 I'm getting this error now Notice: Undefined variable: _SESSION in /srv/www/deadnode.com/public_html/function.php on line 29 Warning: Cannot modify header information - headers already sent by (output started at /srv/www/deadnode.com/public_html/function.php:37) in /srv/www/deadnode.com/public_html/function.php on line 30 I'm assuming it cannot see that session has been started, because its started within the function? 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.