Jump to content

Recommended Posts

use sessions. for example:

page1.php
[code]
<?php
   session_start();

   $_SESSION['blah'] = 'blahblahblah';

   echo "<a href='page2.php'>link to page 2</a>";
?>
[/code]

page2.php
[code]
<?php
   session_start();
  
   if($_SESSION['blah']) {
      echo $_SESSION['blah'];
   }
?>
[/code]
I keep getting the warning:

Warning: session_start(): Cannot send session cookie - headers already sent by...

Everytime it comes to a page with session_start() in it. Why is this?

Also, I'm not sure if it's the same problem, but it doesn't seem to be sending data. My code:

[code]
<?php
           session_start();
           require("functions.php");
if (!validate($_POST['name'], $_POST['password'])) {
                   echo "Login error, please try again.  You will be redirected back to whence you came...";
                   $_SESSION['error'] = 1;
                   echo "<script language=\"JavaScript\"> window.location=\"index.php\"</script>";
           }
           else {
                   echo "Login successful.  Redirecting to the admin page...";
                   echo $_POST['name']." ".$_POST['password'];
                   $_SESSION['name'] = $_POST['name'];
                   $_SESSION['password'] = $_POST['password'];
                   echo "<script language=\"JavaScript\"> window.location=\"main.php\"</script>";
           }
?>
[/code]

Which validates it successfully. However, when I send the page to main.php:

[code]<?php
     session_start();
     require("functions.php");

     if (!validate($_SESSION['name'], $_SESSION['password'])) {
             $_SESSION['error'] = 1;
             echo "Error<br>";
             echo "\"".$_SESSION['name']."\"  \"".$_SESSION['password']."\"<Br>";
             echo "<script language=\"JavaScript\"> window.location=\"index.php\"</script>";
     }
?>
[/code]

It fails and sends me back to index.php. As you can see, I echo'ed out the data, and I get:

"" ""

So why is this happening?
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.