0

Hey everyone I just started using a new hosting service called 1and1 all the normal pages are going fine that use the simple html extension. However one of my php pages that uses the session_start() and header() functions isnt working correctly and I get an error. Now I know an error usually occurs if you have the session_start() below any html code. However I made sure to keep my session_start() and most of my php code above the html. I even tried moving all of it above the html. However I still get the error. Here is my code in its current state: (all areas that have sensitive have been censored of course)

<? 
session_start();
			
  //attempts to connect to DB if it cannot, produces error message 
     if( !($conn= @mysql_connect("******","*****","****")))
           {  
             die("Connection Failed");
           }
   //attempts to select DB if it cannot, produces error message
     if(!mysql_select_db("*****",$conn))
          {
             die("Selection Error");
          }


    //pulls information from the user form 
             $user = $_REQUEST['user'];
             $pass = $_REQUEST['pass'];
             
    //encrypts password 
    
$pass= md5($pass);        
         //creates the query that will check if the user is actually in the database
             $userQ = "SELECT uname FROM `users` WHERE uname = '$user' AND pass = '$pass'";

        ?>
       <?php
              //checks to see if the information supplied by the user matches a name in the database. If not kicks the user to the blamnation page
              if(mysql_num_rows(mysql_query($userQ,$conn)))
                 {
                     //creates an array for the page
                     $userInfo = array();
                     //takes the variables from the session and puts them into an array
                     $userInfo['name'] = $user;
                     $userInfo['pass'] = $pass;
   
                      //creates an array that will fill the array created  above with the data from the databse
                     $fillQ= mysql_query("SELECT uID,xlive,steam,psn,bio,avatar,email FROM users WHERE uname = '$user' AND pass = '$pass'",$conn); 
    
            //fills in the userInfo array with all info on user from database
               while($row = mysql_fetch_assoc($fillQ))
                       {
                         $userInfo['id'] = $row['uID'];
                         $userInfo['picture'] = $row['avatar'];
                         $userInfo['email'] = $row['email'];
                         $userInfo['xlive']= $row['xlive'];
                         $userInfo['psn']= $row['psn'];
                         $userInfo['steam']=$row['steam'];
                         $userInfo['bio'] = $row['bio'];
                       }   
              
            //confirmation text that is displayed to the user if the login is successful   
            $_SESSION['userInfo'] = $userInfo;  
              echo"<div style='width:400px; background-color:#3A3636; margin-left:380px; height:150px;'>";
       echo"<address style='background-color:orange; color:white; font-family:Impact; font-size:25pt;'>Welcome Back!</address>";
       echo"<center>";
     
	      echo "<br> <span style='color:white; font-family:calibri; font-size:12pt;'>Congrats <b>$user</b> you are now logged in </span> <br>";
            echo " <a style='font-family:calibri; font-size:12pt; color:red;' href='blam.php'>Go to Homepage </a> <br>'"; 
            echo " <a style='font-family:calibri; font-size:12pt; color:red;'href='profile.php?profile=$user'>Go To Your Profile </a> <br>";
            echo "<a style='font-family:calibri; font-size:12pt; color:red;' href='pedit.php'> Edit Your Profile</a>";

        echo" </center>";
   
    echo"</div>";



          }
          
       else
         {
           header('location:blamnation.php');
         }
          
       ?>
     


<!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">
<!-- Script that runs to log the user in --> 
 <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Login</title>
 </head>

 <body>

  <br/>
  <!-- creates a box that holds the login confirmation text --> 

     
        

 </body>

</html>

any help guys would be greatly appreciated! thanks!

Edited by soapyillusion: n/a

4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by soapyillusion
0

It would help if you'd also post the error but a first suggestion would be to use <?php as starting tag instead of your <? on line 1.

0

oh that was an error while pasting my code... I have that normally.. not sure if that even work at all without It. I know there use to be some variations allowed on the php tag.. but I thought the rest where considered obsolete.... Yea still need help on the other part though :/

0
Warning: Cannot modify header information - headers already sent by (output started at /homepages/13/d375219296/htdocs/blam/login1.php:28)

Thats the error I get more stuff with the header which makes no sense over the simple fact the header is placed before any html code...

0

Are you perhaps including this file in another file?

What's on line 28 of /blam/login1.php?

Something I encountered a few days ago: Is your file perhaps saved as UTF-8 with BOM?

0

There are no includes, and I do have user checks on every page...And No I'm using dreamweaver to build my code and by default BOM is unchecked. But I do always use UTF-8 character encoding... should I have it turned on?

Edited by soapyillusion: n/a

0

1.If you are getting error like "Warning: Cannot modify header information - headers already sent by (output started at /path/file.php:1)" it means you've got some output before your header() call or starting a session. *No* output can be sent. that includes whitespace (outside of <?php and ?>) and any (X)HTML. You can also use output buffering

try placing this at the top of your page:
<? ob_start(); ?>

then at the bottom of the page place this line of code:

<? ob_flush(); ?>

Edited by IIM: n/a

0

Kudos on the awesome avatar lol XD.
I finally figured it out guys, the stupid server had some very important setting turned on if the php.ini file. Stuff they didn't want me to find or change... but I got my ways arround it ;-). I don't recommend this 1&1 to anyone. I'm stuck for a year.... though.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.