Jump to content

Recommended Posts

This is the error im getting

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/xgame/public_html/random/edit_profile.php:1) in /home/xgame/public_html/random/edit_profile.php on line 2
You must be logged in to edit your profile.

And this is my code

[code]<?php
      session_start();
  ob_start();
      require("config.php");
      require("func.php");
      //echo some styles to spice it up...
      echo "
      <style>
      body
      {
      background: #131313;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      .register_box
      {
      border: 1px solid #323232;
      background: #202020;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      </style>
      ";
      if(isset($_SESSION['logged_in']))
      {
      $session_username = $_SESSION['username'];
      // further checking...
      if(username_exists($session_username))
      {
      $get_info = mysql_query("SELECT email FROM users WHERE username = '$session_username' LIMIT 1");
      if(mysql_num_rows($get_info) > 0)
      {
      $user_info = mysql_fetch_assoc($get_info);
      if(!isset($_POST['do_edit']))
      {
      echo '
      <form action="edit_profile.php" method="post">
      <input type="text" name="email" value="' . $user_info['email'] . '" />
      <br />
      <input type="submit" name="do_edit" value="Edit Your Profile" />
      </form>
      ';
      }
      elseif(isset($_POST['do_edit']))
      {
      $email = mysql_real_escape_string($_POST['email']);
      // assign all errors to an array
      $errors = array();
      if(empty($email))
      {
      $errors[] = 'Your email was empty.';
      }
      if(!is_valid_email($email))
      {
      $errors[] = 'Your email was not in a valid email format.';
      }
      // if array elements is greater than 0,
      // then we KNOW there was an error
    // else, no error, move on to processing
      if(count($errors) > 0)
      {
      echo '<b>ERRORS:</b><br />';
      foreach($errors as $err)
      {
      echo $err . '<br />';
      }
      }
      else
      {
      // everything is ok, update the DB
      mysql_query("UPDATE users SET email = '$email' WHERE username = '$session_username'");
      echo 'Profile Edited.';
      }
      }
      }
      else
      {
      echo 'Could not find profile info for your username.';
      }
      }
      else
      {
      echo 'Sorry, your session username doesnt exist.';
      }
      }
      else
      {
      echo 'You must be logged in to edit your profile.';
      }
  ob_end_flush();
      ?>[/code]

I added

ob_start(); at the beggening and ob_end_flush(); Because i read that it could solve the problem but it didnt.
Link to comment
https://forums.phpfreaks.com/topic/30988-solved-help-session-problem-amp-header/
Share on other sites

as ken said - check for code before the < ?php, even if you cant see anything. go DIRECTLY to the left of the very first < and press backspace a couple of times, save it, and try again.

the sticky at the top of the php help forum (header/session errors) will explain several causes and solutions, but 9/10 in this case, it's due to something being output to the browser before your 'session_start'.

cheers
There was 1 space actually that i missed, now the error is gone but i still have an error saying that im not logged in.

Please check it out yourself.

http://xgame6overx.com/random

Just use supermerc as username and ilmilm as password unless you want to register.

Click My profile to see what im trying to do.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.