Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 51
  1. #1
    New Coder
    Join Date
    Mar 2012
    Location
    United Kingdom
    Posts
    30
    Thanks
    7
    Thanked 0 Times in 0 Posts

    PHP Session_Start()

    Hello All,

    Firstly, thank you for taking the time to resolve my issue. The script was built to build up lead generation for my company. However I have come across a problem I haven't come across before.

    if you go to bmandcoweb.co.uk/email.php the script works perfectly.

    However when I try and intergrate this with other pages within my domain name. It doesn't work.

    The Below Code
    .co.uk/email.php

    The blow code is simple. Once the user submits it's company name (username) and e-mail address an e-mail is sent with a download link. I still need to clean up how the e-mail is sent but this is irrelevant at the moment.

    PHP Code:
    <?php
    require('includes/init.php');

    ?>
    <div align="center">
      <h2 >Email Form</h2></div><br />
    <div align="center" style="width: 600px; margin: 0 auto;">
    <?php
    if(isset($_POST['username'], $_POST['email'])){
        
    $username mysql_real_escape_string($_POST['username']);
        
    $email    mysql_real_escape_string($_POST['email']);
        
    $errors   = array();
        
    $get_dom  end(explode('@'$email));
        if(empty(
    $username)||empty($email)){
            
    $errors[] = 'You must fill in both fields.';
        } else {
            if(
    mysql_result(mysql_query("SELECT COUNT(`id`) FROM `companies` WHERE `username`='$username'"), 0) == 1){
                
    $errors[] = 'That username already exists.';
            }
            if(
    filter_var($emailFILTER_VALIDATE_EMAIL) === false){
                
    $errors[] = 'E-mail address is not valid.';
            }

        }
        if(!empty(
    $errors)){
            foreach(
    $errors as $error){
                echo 
    '<font size="+1" color="#FF0000">'.$error.'</font><br />';
            }
        } else {
            
            
    mysql_query("INSERT INTO `companies` (`id`,`username`,`email`) VALUES ('','$username','$email');");
            
    $body 'Welcome, '.$email.'!

    This e-mail is to verify that your deatails are correct and to download our executive summary document.

    <a href="pdf/executive-summary.pdf.pdf">Download Ececutive Sumary</a>
    <br />
    Your Company Name is: '
    .$username.
    '
    ;
            
    mail($email'You have submitted your details'$body'From: brian@bmandco.co.uk');
            print(
    'Details Submitted!');
        }
    }

    ?>
    <form action="" method="post">
    <p>Company Name:<br /><input type="text" name="username" maxlength="35" /></p>
    <p>E-Mail Address::<br /><input type="text" name="email" maxlength="255" /></p>
    <p><input type="submit" value="Submit Details" /></p>
    </form>
    </div>
    The Blow Code
    includes/init.php
    The database and passwords are included as normal.
    PHP Code:
    <?php
    ob_start
    ();
    session_start();
    mysql_connect('localhost''database','password');
    mysql_select_db('database');
    require(
    'functions/codes.func.php');
    require(
    'functions/wsite.func.php');

    require(
    'functions/users.func.php');
    if(
    $_SERVER['PHP_SELF'] == '/account/edit.php'){
        
    $profile_emotes_show '<script src="/javascript/emotes.js" type="text/javascript"></script>
    '
    ;} elseif($_SERVER['PHP_SELF'] == '/account/upload-vid.php' || $_SERVER['PHP_SELF'] == '/account/upload-music.php' || $_SERVER['PHP_SELF'] == '/account/upload-img.php' || $_SERVER['PHP_SELF'] == '/account/upload-work.php') {
        
    $show_upload_emotes '<script src="/javascript/upload_emotes.js" type="text/javascript"></script>
    '
    ;} elseif($_SERVER['PHP_SELF'] == '/account/profile.php') {
        
    $profile_show '<script src="/javascript/sho_emo.js" type="text/javascript"></script>
    '
    ;} elseif($_SERVER['PHP_SELF'] == '/admin/edit-upload.php') {
        
    $edit_upload '<script src="/javascript/upload_emotes.js" type="text/javascript"></script>
    '
    ;}
    ?>
    if you go to the bmandcoweb.co.uk website you'll find that it's claiming it can't work because of

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/bmandco/public_html/index.php:36) in /home/bmandco/public_html/includes/init.php on line 3

    however it works perfectly in .co.uk/email.php

    Please shed some light on this - Please

    Brian
    Last edited by ShaneC; 04-21-2012 at 04:15 AM. Reason: I forgot my manners

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Brian,

    For some reason the error message says the error has occurred in index.php yet you've chosen to show us email.php which you openly admit works without a problem.

    How do you expect us to advise you on what is wrong and how to fix index.php if you're not going to show us the code? Why are you showing us the code for email.php which you say works and has no problems?

    All is not lost however. If you don't want to show us the code for index.php (which you've made quite clear by not posting it despite knowing its at fault) then I have a handy TIP in my signature which explains this error and how to deal with it. I would recommend you read it as it may help you to resolve your problem yourself.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    You'll want to go ahead and switch the following lines in init.php.

    Change:

    Code:
    ob_start();
    session_start();
    to

    Code:
    session_start();
    ob_start();
    For more detail on this area, see this article.

    And thank you for the politeness! Always appreciated.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • Users who have thanked ShaneC for this post:

    BrianMartin&Co (04-21-2012)

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    @ShaneC: No, if init.php works fine with email.php and NOT for index.php then the order of those two lines will make no difference (I had initially thought the same thing). The problem here is that (as the message says) the headers have already been sent because output has already been sent to the browser in index.php somewhere.

    Even in the article it quite clearly shows that you can do this:
    PHP Code:
    //Start buffering the output
    ob_start();

    print(
    "Some text");

    //Since the output is now buffered, the above statement will not cause any error
    session_start(); 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Quote Originally Posted by tangoforce View Post
    @ShaneC: No, if init.php works fine with email.php and NOT for index.php then the order of those two lines will make no difference (I had initially thought the same thing). The problem here is that (as the message says) the headers have already been sent because output has already been sent to the browser in index.php somewhere.
    And yet if output buffering is enabled content won't be sent to the browser until flush or termination.

    I will concede that, after looking at the error again, the problem may well be in the index.php file (I erroneously assumed it was in init). I would still recommend the original poster make the modification I suggested, however, to alleviate future confusion.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • Users who have thanked ShaneC for this post:

    BrianMartin&Co (04-21-2012)

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    I've already looked at the article and it clearly shows the opposite of what you've actually said about those two lines. Note that output buffering is started inside init.php - not inside index.php as far as we know.

    The point is that Brian has clearly stated that the init.php file works fine with another file but not for the file that claims its already sent its headers. If init.php works fine elsewhere then it's nothing to do with the order of those two lines.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    New Coder
    Join Date
    Mar 2012
    Location
    United Kingdom
    Posts
    30
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Hey thanks for those tips. The swaping line session and line ob_start(); didn't work

    However; I didn't want to post the entire index.php as I'm using functions, the problem occurs on every page so what makes index.php different to say seo-services.php ect


    Brian

  • #8
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Quote Originally Posted by BrianMartin&Co View Post
    Hey thanks for those tips. The swaping line session and line ob_start(); didn't work

    However; I didn't want to post the entire index.php as I'm using functions, the problem occurs on every page so what makes index.php different to say seo-services.php ect


    Brian
    And yet we really need to see that page in order to help you, especially if your functions are what's causing the problem.

    If you don't want it publicly posted, feel free to PM it to me. Otherwise, please post at the very least lines 30 to 40 of index.php.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • Users who have thanked ShaneC for this post:

    BrianMartin&Co (04-21-2012)

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by BrianMartin&Co View Post
    Hey thanks for those tips. The swaping line session and line ob_start(); didn't work
    No it won't because as I've said, you have output starting in your other pages before your inclusion of init.php. It works in email.php because it's included straight away.

    Quote Originally Posted by BrianMartin&Co View Post
    However; I didn't want to post the entire index.php as I'm using functions, the problem occurs on every page so what makes index.php different to say seo-services.php ect
    Functions or no functions, you're going to have to show something codewise. I've already said that line swapping wouldn't resolve this so you have two options:
    1) Post code
    2) Read the tip in my signature, modify your pages to use output buffering at the top of the code rather than inside init.php.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #10
    New Coder
    Join Date
    Mar 2012
    Location
    United Kingdom
    Posts
    30
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Hey,

    I have PM'd you both.

    Again, thank you for your time and patients.

    Brian

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by BrianMartin&Co View Post
    I have PM'd you both.
    Nope, you've not PM'd me so despite being able to see the fault from the first reply I made, you've chosen to ignore my help and advice and instead go with ShaneC's who was wrong (I presume because he's a Mod you thought he'd be a better bet?)

    Well, not much I can say to that is there other than good luck - I will assist no more.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #12
    New Coder
    Join Date
    Mar 2012
    Location
    United Kingdom
    Posts
    30
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I did try that and it didn't work. Perhaps I've done something wrong.

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Two minutes after my post you decide to PM me...

    The cause is immediately obvious:

    The first line in your index.php page is html code - OUTPUT THAT TRIGGERS YOUR HEADERS. Didn't you read the tip in my signature?

    The very first thing you should have at the top of the file is this:
    <?php require('includes/init.php'); ?>

    It should look like this:
    PHP Code:
    <?php require('includes/init.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    Last edited by ShaneC; 04-21-2012 at 02:57 AM. Reason: OP's code removed by request
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #14
    New Coder
    Join Date
    Mar 2012
    Location
    United Kingdom
    Posts
    30
    Thanks
    7
    Thanked 0 Times in 0 Posts
    That was one of the things I done first in the early stages of attempting to solve my issue. and yes although it takes the error messages away from the website. the script now doesn't work.

    It wont send the e-mail.

  • #15
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Well now that the file has been posted, and tangoforce and I have both told the original poster the same advice, it's probably best to converge back here.

    The original poster specified via PM that adding <?php require('includes/init.php'); ?> to the top of the file does not fix the error. OP: Please double check that when you add that line to the top of index.php that you also remove it from wherever it is currently called.

    If that still doesn't fix your problem, it may be helpful to see the contents of <?php include("functions/container.php");?>, which is referenced in the PHP error.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • Users who have thanked ShaneC for this post:

    BrianMartin&Co (04-21-2012)


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •