Jump to content


Photo

Manually Adding Post Data


  • Please log in to reply
3 replies to this topic

#1 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 28 June 2006 - 02:38 AM

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?

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 28 June 2006 - 02:42 AM

use sessions. for example:

page1.php
<?php
   session_start();

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

page2.php
<?php
   session_start();
  
   if($_SESSION['blah']) {
      echo $_SESSION['blah'];
   }
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 28 June 2006 - 03:08 AM

Thanks! Exactly what I was looking for.

#4 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 28 June 2006 - 03:28 PM

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:

<?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>";
           }
?>

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

<?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>";
     }
?>

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users