rshadarack Posted June 28, 2006 Share Posted June 28, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/13067-manually-adding-post-data/ Share on other sites More sharing options...
.josh Posted June 28, 2006 Share Posted June 28, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/13067-manually-adding-post-data/#findComment-50280 Share on other sites More sharing options...
rshadarack Posted June 28, 2006 Author Share Posted June 28, 2006 Thanks! Exactly what I was looking for. Quote Link to comment https://forums.phpfreaks.com/topic/13067-manually-adding-post-data/#findComment-50287 Share on other sites More sharing options...
rshadarack Posted June 28, 2006 Author Share Posted June 28, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/13067-manually-adding-post-data/#findComment-50443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.