Jump to content

Archived

This topic is now archived and is closed to further replies.

rshadarack

Manually Adding Post Data

Recommended Posts

I wish to add data via $_POST without using a form, but I can't seem to find a function that will allow me to do this. Is there one? If not, how else can I go about passing hidden data between pages?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

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.