php sessions not working?

itman647

New Member
Messages
45
Reaction score
0
Points
0
hey there x10hosting, im just curious as to why the error message keeps on coming up in my website every time i start a new session using php? is it the php configuation i have? can you upgrade me to the advanced php config if so?

okay so this is what I have at the top of one of my pages

<?php
session_start();
?>

when I save and view the page in the browser the following error messages are returned.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/itman647/public_html/videodown/beta/indexed.php:1) in /home/itman647/public_html/videodown/beta/indexed.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/itman647/public_html/videodown/beta/indexed.php:1) in /home/itman647/public_html/videodown/beta/indexed.php on line 2

basically what I need the session php function for, is to send data from one page to another without having to use forms, etc... basically so that my members can surf my webpages with ease instead of having to submit lots of forms to transfer the members details from one page to another, using loads of forms could clog the server and its traffic. im quite advanced with php but just can't find the time to use forms as an alternative method because im currently doing my a-levels. so instead i just want to ease off lots of lines of coding to save time and processing power.

thanks guys
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
This is a problem with you script not the x10 Servers. Basically your script is outputting information to the user's browser before you call the session_start() function.
session_start() need to be right at the top of the script.

*Moved to Programming Help*
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
the line

<?php
session_start();
?>

is right at the top of my page before anything else including the document type declaration

but it still outputs the same error message?

I thought it might be because i dont have the advanced php configuation. and im not sure why x10 wont give me the full version because im quite experianced with php.

so is it the php config or just my programming?

this is the html

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-gb">
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Control Panel<title>
<style type="text/css">
a {
color: #4D4D4D;
}
a:visited {
color: #A1C040;
}
a:active {
color: #C6E666;
}
a:hover {
color: #FFFFFF;
}
</style>
</head>
<body style="margin: 0; background-color: #333333">
</body>
</html>

and this is the output

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/itman647/public_html/videodown/beta/indexed.php:1) in /home/itman647/public_html/videodown/beta/indexed.php on line 1

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/itman647/public_html/videodown/beta/indexed.php:1) in /home/itman647/public_html/videodown/beta/indexed.php on line 1


help!
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
Have you upgraded from basic? That could be the problem. It's certainly not x10's servers as I've never had a problem with Sessions before.
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
yeah about 3 months ago i think, but i havent used sessions until now so im not sure if it worked before the upgrade?
Edit:
thats weird it only shows 1 message now

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/itman647/public_html/videodown/beta/indexed.php:1) in /home/itman647/public_html/videodown/beta/indexed.php on line 1
Edit:
thats weird it only shows 1 message now

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/itman647/public_html/videodown/beta/indexed.php:1) in /home/itman647/public_html/videodown/beta/indexed.php on line 1
 
Last edited:

Jake

Developer
Contributors
Messages
4,057
Reaction score
5
Points
0
Are you by any chance using a header("Location: index.php"); to get to your script here? because if so... the location changes but all headers are still initialized thus making it give an error... unless you have the header(); also above all the HTML in your document.
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
nope i havent included any header function in my site

im not sure because on firefox it says both error messages and on IE it shows just one, and to make sure that all the changes I've made in expression web have taken effect I press ctrl and f5 to full refresh the code. this is weird.
Edit:
do you think that resetting everything back to normal would solve this?
like resetting all the htmlaccess files, logs, php files, etc. because i wouldn't mind that option lol as long as it works
 
Last edited:

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
Your PHP version will not affect this, and resetting your account won't help. It is something in the script that is causing the problem.
Is there a new line or a space at the top of the file?
 

Nahid_hossain

New Member
Messages
28
Reaction score
0
Points
0
you can add this line at the top of your script to hide error message
PHP:
<?php error_reporting(0); ?>

remember this won't solve the issue, just hide the error message. To solve the issue you need to use session_start(); before any of your output. (i.e any header or html or any client side language). If you are not sure then put if at the top of your script just after the first <?php
 

Jake

Developer
Contributors
Messages
4,057
Reaction score
5
Points
0
Im assuming he wants the session to be initialized but if you were to stop all errors then you would be letting it run without a session =/ same as if you just deleted session_start();
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
this is a weird issue, because i type the full address in, i dont use a header function to access the page from another one and if i did i would take a look at the previous page and check if anything has been started, and yet i've tried initilizing the session function by placing the <?php session_start(); ?> right at the top of the page, im clueless? oh well i might just start the whole project from scratch
Edit:
Your PHP version will not affect this, and resetting your account won't help. It is something in the script that is causing the problem.
Is there a new line or a space at the top of the file?

oh so the session function is available with every single php configuration, ive got the intermidiate btw.

okay this is what i've done i've made a quick new page with the following php code

<?php
session_start();
$user = $_GET['user'];
$pass = $_GET['pass'];
echo "<hr>Logging In...<hr>";
$_SESSION['ses_user'] = $user;
$_SESSION['ses_pass'] = md5($pass);
echo $_SESSION['ses_user']."<hr>";
echo $_SESSION['ses_pass'];
?>

okay you can try it for yourself here is the absolute link to the page im talking about:

http://glitcherselite.exofire.net/?user=itman647&pass=12345

okay try that out, it all works even though it has created a error message. weird? i think you might need to take a look at the server files or something? tried it out on FF and IE and both produce the same results?

------------
UPDATE
------------

I'm now using the error_reporting(0) function to get rid of the error messages which is a bit annoying. but I still wanna know why the page keeps on saying there's an error even though it works? I shouldn't have to use error_reporting, because now to check that every other php script works I have to keep on removing and adding 'error_reporting(0)' from the top of my php pages whenever I edit them.
 
Last edited:

souradipm

New Member
Messages
45
Reaction score
0
Points
0
Doesnt show any warnings for me
Logging In...
-----------------------
itman647
-----------------------
827ccb0eea8a706c4c34a16891f84e7b
 
Last edited:

souradipm

New Member
Messages
45
Reaction score
0
Points
0
You have something before the <?php tag. PHP reports session_start() as line 3, and because it is directly under the <?php tag, you have something on line 1 - a newline perhaps? session_start sends a header for the browser to start a session, and it cannot modify them after they have been sent - they are sent when an echo command is executed or any other form of output.
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
i think it might be PHPLib or another program installed on the server which might execute code before it executes the page's php
because it works and everything just this stupid message keeps ruining my page
heres the php and yes it is indeed on line 3
01 <?php
02
03 session_start();
04
05 $user = $_GET['user'];
06 $pass = $_GET['pass'];
07
08 echo "<hr>Logging In...<hr>";
09
10 $_SESSION['ses_user'] = $user;
11 $_SESSION['ses_pass'] = md5($pass);
12
13 echo $_SESSION['ses_user']."<hr>";
14 echo $_SESSION['ses_pass'];
15
16 ?>
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
lol thats what I mean but the admins who run x10hosting say its not the server its your coding. I'm gonna ask them to reset all my php config files, htaaccess files, etc. Maybe that'll get rid of the problem, because Iam an experianced coder and can easily spot a obvious mistake
 

Jake

Developer
Contributors
Messages
4,057
Reaction score
5
Points
0
yeah thew php.ini file might be different than normal... try upgrading your php to advanced. Also yeah I couldn't see anything wrong with it either lol
 

itman647

New Member
Messages
45
Reaction score
0
Points
0
YES!!

I'AM A GENUIS, I'VE FIGURED OUT WHAT IT IS BY MYSELF LOL. I DONE A LITTLE BIT OF RESEARCH ON THE NET ABOUT THIS HEADER AND THE MAJORITY SAID THAT IT MAY BE CAUSED DUE TO WHITESPACE OR INVALID CHARS BEFORE AND AFTER THE <?PHP TAGS. SO I CHECKED USING MICROSOFT EXPRESSION WEB. NO CHARACTERS OR WHITESPACES BEFORE OR AFTER THE <?PHP TAGS. SO THEN I THOUGHT TO MYSELF, WHAT COULD CAUSE THIS, MY CODING IS EXCELLENT? THEN IT CAME TO ME LIKE A BOLT OF LIGHTNING, THE ENCODING. THE FILE ON EXPRESSION WEB CONVERTS THE FILE TO A UTF-8 FORMAT. WHEN I VIEWED THE INDEX.PHP FILE USING THE ONLINE EDITOR AND VIEWED THE FILE IN US-ASCII FORMAT THERE WERE 3 SQUARES WHICH JUST APPEARED BEFORE THE <?PHP TAG. THEY WEREN'T THERE WHEN I VIEWED IT IN UTF-8. SO I REMOVED THEM AND SAVED THE FILE IN US-ASCII FORMAT. AND WHEN I REFRESHED THE WEBPAGE, THE WARNING ... GONE!. YAY.

I THINK MY EXPRESSION WEB PROGRAM MIGHT NEED TO BE UPDATED OR SOMETHING LOL BECAUSE I CAN'T CHANGE THE DEFAULT ENCODING TYPE IT'S ALWAYS SET TO UTF-8 WHEN I WANT IT IN US-ASCII SO I CAN EASILY SOLVE THIS IN THE FUTURE.

HEY THANKS FOR THE SUPPORT BTW souradipm AND JAKE, I KNEW MY CODE WAS CORRECT, DAMM STUPID ENCODING CRAP LOL.

I THINK ITS A SIGN TO GET A NEW WEBSITE EDITOR LOL, AT LEAST ONE THAT ENCODES PROPELY
 
Last edited:

Jake

Developer
Contributors
Messages
4,057
Reaction score
5
Points
0
Good job!... thus why Dreamweaver is my friend.
 
Top