Jul 20, 2008

Session_start() - whats going on with it

Free Web Hosting, No Ads > CONTRIBUTE > The Internet > Website Discussion

free web hosting

Session_start() - whats going on with it

illdevilinc
Hi im using my page in php coding and the session_start() code is messing something up.
This is the error:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/idimm/public_html/index.html:2) in /home/idimm/public_html/index.html on line 103

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/idimm/public_html/index.html:2) in /home/idimm/public_html/index.html on line 103:
Does anyone know how to fix this? It does do the command but it gives this annoying error message no madder what. Please help i would like to get this feature working on my site. This is being a very hard code. Stupid PHP. But heres the url for the site if you want to go to it and see the error your self. The error page.
thanks,
me

Reply

Hat
index.html has to be changed to .php for one thing...and thats I'm all I'm good for, because I suck at PHP.

Reply

jlhaslip
Well there is a problem right at the top of your page which needs to be sorted out before you get any further along. There are some things way out of place and missing.
The typical sequence for an html (or htm) page should be something like this:
CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="shortcut icon" href="favicon.ico" />
<link href="something.css" rel="stylesheet" type="text/css" media="all">
  <title>Demo title</title>
  <style type="text/css" media="screen">
<!-- Insert the embedded styles here -->
  </style>
<script type="text/javascript">
onload = function() { content.focus() }
</script>
</head>
   <body>

<!-- Main Html Code for the page -->

</body>
</html>


I did a view source of the trap17 page to snag some of this, so it might not be exactly what you want, but the order of the tags is what I was attempting to show you. The Doc Types must be exactly coded or they will blow up pretty quickly.
Now do a view > source of your page and compare the two.
You don't have a Doc Type, the first tag is a style tag, there are several other things there to fix up before you get to the Header problem.

After you have fixed these things as best as you can, run the page through the w3c Validator at their site, www.w3c.org, to make sure it passes. The validation won't check logic or php errors, but it will tell you if all is well with the syntax of the page.

As for the Headers, see the php manual at http://ca.php.net/manual/en/function.header.php. There are also rules about how to send the Cookies used for the sessions.
QUOTE

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.

 

 

 


Reply

illdevilinc
QUOTE(Hat @ Mar 9 2006, 01:14 PM) *

index.html has to be changed to .php for one thing...and thats I'm all I'm good for, because I suck at PHP.

I am using a .htaccess file so i dont need to change the type of page.

QUOTE(jlhaslip @ Mar 9 2006, 01:57 PM) *

Well there is a problem right at the top of your page which needs to be sorted out before you get any further along. There are some things way out of place and missing.
The typical sequence for an html (or htm) page should be something like this:
CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="shortcut icon" href="favicon.ico" />
<link href="something.css" rel="stylesheet" type="text/css" media="all">
  <title>Demo title</title>
  <style type="text/css" media="screen">
<!-- Insert the embedded styles here -->
  </style>
<script type="text/javascript">
onload = function() { content.focus() }
</script>
</head>
   <body>

<!-- Main Html Code for the page -->

</body>
</html>


I did a view source of the trap17 page to snag some of this, so it might not be exactly what you want, but the order of the tags is what I was attempting to show you. The Doc Types must be exactly coded or they will blow up pretty quickly.
Now do a view > source of your page and compare the two.
You don't have a Doc Type, the first tag is a style tag, there are several other things there to fix up before you get to the Header problem.

After you have fixed these things as best as you can, run the page through the w3c Validator at their site, www.w3c.org, to make sure it passes. The validation won't check logic or php errors, but it will tell you if all is well with the syntax of the page.

As for the Headers, see the php manual at http://ca.php.net/manual/en/function.header.php. There are also rules about how to send the Headers.

The page was generated by Microsoft Frontpage 2003. The headers were automaticly generated by frontpage and the code has been checked by it. Im not sure if this is the problem because the problem is that i am putting the php code in a TABLE and it requires a seesion_start() which i have just found out that it must be on the top of the page to function properly. If i put the whole code up on the top it works fine but if it is in the table i get a error. I have no idea how to get it to work in the tables but i am experimenting with it and everything so far has failed. If anyone has any information on how to put this kind of code in a table please help me.
here is the code
CODE
<?php
session_start();
//check to see if the user already has an open session
if (($_SESSION[user_name] != "") && ($_SESSION[password] != ""))
{
    echo"Favorites--Logout";
}
else
    echo"Login";
?>

and here is the code for the shared border that this code is in
CODE
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Shared Top Border</title>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="none">
<meta name="Microsoft Border" content="none">
</head>

<body>

<p align="left"><font color="#808080" size="2"><br>
</font><font color="#FFFF00">We Now support
<script type="text/javascript"><!--
google_ad_client = "pub-7806936936690646";
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = "180x60_as_rimg";
google_cpa_choice = "CAAQ24Oy0QEaCGbgW7AaXRokKMu293M";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br>
</font><font size="2">
<!--webbot bot="Navigation" s-type="top" s-orientation="horizontal" s-rendering="graphics" b-include-home="TRUE" b-include-up="TRUE" s-theme="classic 0010" --></font></p>
<div style="position: absolute; width: 100px; height: 100px; z-index: 16; left: 740px; top: 16px" id="layer21">
    <p align="center"><!--webbot bot="HTMLMarkup" startspan --><form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="illdevilinc@gmail.com">
<input type="image" src="https://www.paypal.com/en_US/i/btn/view_cart.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="display" value="1">
</form><!--webbot bot="HTMLMarkup" endspan --></div>
<p align="center"><font size="2">
<img border="0" src="../images/IDI%20METAL%20MUSIC%20LOGO.JPG" width="84" height="65" alt="Metal Music" align="left"></font></p>
<div style="position: absolute; width: 505px; height: 62px; z-index: 10; left: 181px; top: 233px" id="layer14">
    <p align="center">Advertisement<font size="1">▼</font>
    <script type="text/javascript"><!--
google_ad_client = "pub-7806936936690646";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "333333";
google_color_bg = "000000";
google_color_link = "FFFFFF";
google_color_url = "999999";
google_color_text = "CCCCCC";
//--></script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"> </p>
<table border="1" width="100%" id="table2">
    <tr>
        <td><?php
session_start();
//check to see if the user already has an open session
if (($_SESSION[user_name] != "") && ($_SESSION[password] != ""))
{
    echo"Favorites--Logout";
}
else
    echo"Login";
?></td>
        <td> </td>
        <td> </td>
    </tr>
</table>
<div style="position: absolute; width: 510px; height: 100px; z-index: 17; left: 181px; top: 327px" id="layer22">
    <p align="center">Need to find something?  Then search our site! 
    (Provided by Google)<br>
    <!--webbot bot="HTMLMarkup" startspan --><!-- SiteSearch Google --> </p>
<form method="get" action="http://www.google.com/custom" target="google_window">
    <table border="0" bgcolor="#000000">
        <tr>
            <td nowrap="nowrap" valign="top" align="left" height="32">
            <p align="right"></td>
            <td nowrap="nowrap" align="center">
            <input type="hidden" name="domains" value="metalmusic.trap17.com">
            <p align="right">
            <input type="text" name="q" size="10" maxlength="255" value>
            <input type="submit" name="sa" value="Google Search"> </td>
        </tr>
        <tr>
            <td>
            <p align="right"> </td>
            <td nowrap="nowrap" align="center">
            <table>
                <tr>
                    <td>
                    <p align="right">
                    <input type="radio" name="sitesearch" value checked="checked">
                    <font size="-1" color="#ffffff">Web</font> </td>
                    <td>
                    <p align="right">
                    <input type="radio" name="sitesearch" value="metalmusic.trap17.com">
                    <font size="-1" color="#ffffff">metalmusic.trap17.com</font>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="client" value="pub-#############">
            <p align="right"><input type="hidden" name="forid" value="1">
            <input type="hidden" name="ie" value="##########">
            <input type="hidden" name="oe" value="################">
            <input type="hidden" name="safe" value="active">
            <input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;">
            <input type="hidden" name="hl" value="en"></td>
        </tr>
    </table>
</form>
<p>
<!-- SiteSearch Google --></p>
<!--webbot bot="HTMLMarkup" endspan --></div>
<p align="center"> </p>

</body>

</html>

thank you for the people that are willing to help me

Reply

jlhaslip
Quoted from the php manual $session_start():
QUOTE

NOTE: If you are using cookie-based sessions, you must call session_start() before anything is output to the browser.

Sorry, I mistakenly referenced to the $set_cookies (). So, yes, having the #session_start() in the middle of the tablet, after output has started to the browser will throw an error.

Reply

OpaQue
Check all your INCLUDE / REQUIRE files and see if there is any space left

CODE
after

?>


OR

CODE
Before

<?


Reply

illdevilinc
I have tried callin session_start() before the html coding but i cant have my loogin/logout coding at the top. I am trying to keep them in the table that i have created for them but im not sure how to do it. I have tried caling session start like this:
<?
Session_start()
?>
HTML CODE
<?
LOGIN SCRIPT CODE
?>
But it did not give an error but didnt work. If anyone knows something i could do to call the session before the html but still have the actual login/logout script in the table please tell it to me.
Im sorry i wasnt clear of my problem.
And thanks for trying to help me!

Reply

jlhaslip
Post the code for the entire page including the Login Script, please. Doing a view source doesn't show the php script or form handling. Might be something there.

Reply

moldboy
You say you want the login in the table with the form. That makes sense, it's the natural way to program, and when I first started php the lack of a goto function drove me crazy. The reason the model you have tried (but can't get to wirk) isn't returning an error is because you set the page up properly. Session_start() must be the first line sent to the browser, so fir example in the following code (I just wrote this there may be errors)
CODE

<html>
<head>
</head>
<body>
<?php
if $sessions == TRUE{
session_start();
};
else {
echo "<p>session were not requested</p>";
};
?>
</body>
</html>

this code will result in an if session == TRUE because it will try to start the session after the browser has recieved code (the <html>... stuff)

Umm, you really need to post a little more code, If you use session_start() at the top of the page so it doesn't return an error, then you should be able to set session variables at any point later in the page. It may very well be the way you are calling the variables that results in it not working.

That's all I can think of right now, without more code, I'm sorry I can't be of more help

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : session, start, whats

  1. Flat Files! Good Or Bad? Whats Your Opinion!
    (5)
  2. Moderator Of A Forum
    What's his tasks (6)
    The title and description says it all, I'm going to start 2 forums and I want to know what's
    the tasks of a moderator in a forum and what he do on it.....
  3. What Forum Software Do You Use And Whats Your Favorite?
    (13)
    Hello everyone I was just wondering what forum software you guys use and why you guys like it. I use
    invision power board 2.2 or am awaiting a host from here to host it /ohmy.gif"
    style="vertical-align:middle" emoid=":o" border="0" alt="ohmy.gif" />....
  4. Blog
    Whats a blog? (0)
    QUOTE A weblog (usually shortened to blog, but occasionally spelled web log or weblog) is a
    web-based publication consisting primarily of periodic articles, most often in reverse chronological
    order. Early weblogs were simply manually updated components of common websites. However, the
    evolution of tools to facilitate the production and maintenance of web articles posted in said
    chronological fashion made the publishing process feasible to a much larger, less technical,
    population. Ultimately, this resulted in the distinct class of online publishing that produces blo....
  5. Whats An Https
    How do you create one? (4)
    I know that HTTPS stands for the normall stuff, and then add secure . But can someone explain how
    these work, or how I can install them on my website, or create a secure directory? Do you need a
    GNUP or SSL or can someone just explain what it does. Thanks, in advanced. /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  6. What's On Your Site?
    (35)
    This is for all of you who have websites. There is an outrageous number of websites out there of all
    different types. I thought it would be interesting to see what kinds of websites everyone has here
    at trap17. So if you have a website (or more than one, not necessarily hosted by trap17), share what
    its about. What do you like to put on your site? Also, provide a link if you can. Even if you dont
    have a website but are planning on making one, share your thoughts and maybe you'll get some
    extra ideas. As for me, I currently do not have a site. I used to have one that....
  7. What's Your Alexa Rating?
    compare alexa ratings (4)
    First, go here: http://www.alexa.com/site/site_stats/signup?mode=stats Then, type in the URL of
    your website. Follow their format or else it won't work. Next, click the Build This button for
    which ever button you want. You have about 3 choices. Finally, right-click on the image generated,
    and paste it here! Here's mine: Pretty good for me because last week, it was around
    34,000. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  8. Whats Your Ideal Site?
    Best features on a site? (8)
    What would your ideal site have on it? I mean like free legal music and stuff like that. Mine would
    have free legal music, lots of good quality games, free downloadable games, free software, wicked
    layout and just general stuff like that. If hteres a site that you think is your ideal site please
    post that here to. Cheers, Karl....
  9. Whats On Your Site?
    what is on your site????? (42)
    hi everyone i just wanted to no what is on your site???? like music games videos i mite get a few
    ideas lol cheers chris....
  10. Php?
    Can any tell me whats so great about PHP (6)
    what the hell is PHP everything i download for my site you need PHP :S wot is sooo gd about it? and
    wots da easyest way 2 use it?????....
  11. Whats Your Favorite Forum System?
    (15)
    Theres tons of forum systems out there, so which one is your favorite? For me it all depends on the
    situation. SMF is my favorite php\MySQL forum system since it blows away any version of IPB,
    and is comparable to VBulletin, while still being incredibly stable, and also it's free. My
    favorite CGI\Perl board is YaBB 2, which is on the exact same level as SMF in terms of features
    (Y2 has some features SMF dosent, SMF has some Y2 dosent). So, whats your guy's favorite forum
    system? /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' />....

    1. Looking for session, start, whats

Searching Video's for session, start, whats
advertisement



Session_start() - whats going on with it



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE