Jump to content

Session Errors


havox

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/219376-session-errors/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/219376-session-errors/#findComment-1137590
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/219376-session-errors/#findComment-1137609
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.