Redirect help and SSL Help
Results 1 to 8 of 8

Thread: Redirect help and SSL Help

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    47

    Redirect help and SSL Help

    I having trouble with my re-direct code on my php registration form. The form does submit data to the database but I'm getting the following error.

    "Warning: Cannot modify header information - headers already sent by (output started at /homepages/25/d232402382/htdocs/testencourage/registration.php:15) in /homepages/25/d232402382/htdocs/testencourage/registration.php on line 87"

    I would like the form goes to the thanks.php after submitting the data but its not doing its job. Here is the code.

    PHP Code:

    <?php

    if ($_SERVER['HTTPS']) { 
    header('location: https://www.fakewebsite.com');
    }

    ?>


     <?php

    if (isset($_POST['submitted'])){
        
    $fields = array(
        
    'email',
        
    'state',
        
    'district',
        
    'gender',
        
    'age',
        
    'profession',

    );

    if (
    safe($_POST['survey']=="Yes")){
        
    $survey "Yes";
    }
    else{
        
    $survey "No";
    }
        

    foreach(
    $fields as $fieldName) {
        if(isset(
    $_POST[$fieldName]) and safe(trim(stripslashes($_POST[$fieldName]))) !==''){
            $
    $fieldName safe(trim(stripslashes($_POST[$fieldName])));
        }else {
            
                    
    $errors[] = "Please enter your"$fieldName .""//code to validate fields
        
    }
    }
    if(!isset(
    $errors)){
        
    require_once(
    'Connections/encourage.php');

    $query "INSERT INTO participants (email, state, district, gender, age, profession, survey, registration_date) 
    VALUES ('
    $email', '$state', '$district', '$gender', '$age', '$profession','$survey', NOW())"//databasse connection
       
        
    $result mysql_query ($query);     



    if (
    $result){
        
        
    $url 'http://'$_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
        
        if ((
    substr($url, -1) == '/') || (substr($url, -1) == '\\')) {
            
    $url substr ($url-1);
        }
        
        
    $url .= '/thanks.php';
        
    header("Location: $url");// this is line 87
        
    exit();
        
        }else{
        
        echo 
    '<h1 id="mainhead">System Error</hl>
        <p>Your registration could not be completed due to a system error We apologize for any incovience</p>'
    ;//gives system error
        
    echo 'p' mysql_error(). '<br /><br />Query: ' $query '</p>';
        exit();
        
        }
        
    mysql_close();
        
        } else { 
            
            echo 
    '<h1 id="mainhead">Error!</h1>
            <p class="error">The following error(s) occurred:<br />'
    ;
            foreach(
    $errors as $msg) {
                echo 
    " - $msg<br/>\n";
            }
            echo 
    '</p><p>Please try again.</p><p><br/></p>';
        }

    }

    function 
    safe($string
        { 
            
    $pattern "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"
            return 
    preg_replace($pattern''$string); 
        }
        
    ?>
    Also I'm going to set up my ssl on the server so I'm planning to use that https redirect syntax but since I'm very new at this, am I missing something. Your help will be greatly appreciated, thanks!

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,774
    What is on line 15 of registration.php? Whatever it is, it's sending output to the browser. Once that's done, you can't send any headers like you're trying to do on line 87.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Member
    Join Date
    Jan 2012
    Posts
    47

    Line 15

    Line 15 is actually the <title> tag of the registration page

    Code:
    <title>The Title of the Fake Website</title>

  4. #4
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,740
    There you go that is output. As weed described (and the error states) you can't have output before headers if you want them to work. Incidently in the snippet you posted you have output before line 87 as well:
    PHP Code:


    ?> 


    <?php 

    if (isset($_POST['submitted'])){
    White-space is output.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  5. #5
    Member
    Join Date
    Jan 2012
    Posts
    47

    okay,

    Okay, I took out the <title> tag and the error went to the next line.

    Apparently, I have this on my code

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Encourage Excellence - Combatting Autism and Encouraging Excellence in Chattanooga Tennessee Registration</title>
    <link href="css/registration.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="content">
    <div id="logo"><img src="images/logo/logo.png" alt="encourage logo" width="113" height="98" border="0" /></div>
    <!--end of logo-->
    <div id="socialmedia"><a href="https://www.facebook.com/EncourageExcellence" target="_blank"><img src="images/navigation/facebook.png" alt="facebook icons" width="54" height="48" border="0" /></a><a href="https://twitter.com/#!/EncourageExcell" target="_blank"><img src="images/navigation/encourage-excellence_04.png" alt="twitter page" width="67" height="48" border="0" /></a><!--<a href="http://www.youtube.com/user/EncourageExcellence" target="_blank">--><img src="images/navigation/youtube.png" alt="youtube page" width="67" height="48" border="0" /></a><a href="http://www.linkedin.com/pub/katherine-cordell/38/189/68a" target="_blank"><img src="images/navigation/linkin.png" alt="linkin page" width="56" height="48" border="0" /></a></div>
    <!--end of social-->
    
    <div id="header"><div id="navigation"><a href="index.html"><img src="images/navigation/navigation-bar/Home.jpg" alt="Home-button" width="182" height="27" border="0" /></a><a href="about.html"><img src="images/navigation/navigation-bar/about-us-.jpg" alt="about-us" width="182" height="27" border="0" /></a><img src="images/navigation/navigation-bar/oasis.jpg" alt="oasis-button" width="181" height="27" border="0" /><a href="contact.html"><img src="images/navigation/navigation-bar/button.jpg" alt="contact-us-button" width="182" height="28" border="0" /></a><img src="images/navigation/navigation-bar/button-08.jpg" width="182" height="28" /><img src="images/navigation/navigation-bar/button-09.jpg" width="182" height="26" /></div>
    <div id="montage"><img src="images/header/header.jpg" width="811" height="164" alt="header" /></div>
    </div><div id="chattheader"><img src="images/header/chatthead.jpg" width="1000" height="29" alt="chattheader" /></div>
    <!--end of header-->
    <div id="disclaimer">
    <div class="disclaimfont" id="infodisclaim">
      <h1>Register to Participate<br />
      </h1>
      <p>The Information you will need to give us so we can send advertisements effectively.</p>
      <div id="formwrapper">
    That's the entire header part of my site. Now, I'm pretty sure that is really causing the issue but I don't want to delete it because I need it. Any solutions?
    Last edited by cybereclipse; 04-13-2012 at 06:43 PM.

  6. #6
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,354
    No one said you had to delete it... you just can't output anything before you try to use header().

    This should make sense and already be part of your application logic anyway; why waste time generating all of that output when later on you throw it all away and try to redirect the user elsewhere?

  7. #7
    Member
    Join Date
    Jan 2012
    Posts
    47
    Okay, what exactly am I suppose to do because I'm still literally lost.

  8. #8
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,354
    Calling header() after you output data won't work and will cause an error. The solution is simple: do the opposite of putting the call to header() after the output (which, in case you're still lost, means putting the call to header() before the output).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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