HaLo2FrEeEk Posted May 6, 2007 Share Posted May 6, 2007 I have no clue if this is possible, and if it is, how to do it. Basically, I am creating a vote server system for my school, there is a central server with IIS, MySQL and PHP 5 on it, and I need to write all the pages that will get the information and display it, allowing the students to vote. I have the index page, which is nothing more than the login page, at least for now. When the student enters his / her student ID, the database checks if it exists by using this query: mysql_query('SELECT count(*) FROM `students` WHERE `snumber` = \''.$sid.'\''); if the number is 1, the ID exists, if it is 0, it does not, simple. I will then transfer the person to vote.php, which will get the person's first and last name and display it at the top, then display all the vote information, and if they exist, poll questions as well. MY question is this, how would I go about transferring the person from index.php (where their student ID is validated) to vote.php where they will be allowed to vote, and also passing their student ID in a POST variable? I don't want to use vote.php to validate becuase I don't want the person to accidentally be able to vote without entering proper information. I also don't want to pass their student ID through GET for obvious reasons. IS there anything I can do? Btw, I don't mean to sound needy, but I am rather rushed on this project, any help will be extremely appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/ Share on other sites More sharing options...
HaLo2FrEeEk Posted May 6, 2007 Author Share Posted May 6, 2007 Bump, comon people, I really need help with this. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246848 Share on other sites More sharing options...
HaLo2FrEeEk Posted May 6, 2007 Author Share Posted May 6, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246880 Share on other sites More sharing options...
kenrbnsn Posted May 6, 2007 Share Posted May 6, 2007 You wouldn't pass it via the $_POST array, you would use a session variable In the index.php <?php session_start(); // // processing ... // $_SESSION['sid'] = $sid; ?> In vote.php <?php session_start(); $sid = $_SESSION['sid']; // // do processing // ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246886 Share on other sites More sharing options...
b1011 Posted May 6, 2007 Share Posted May 6, 2007 it might not b secure, but you could pass it along using $_GET[''] things. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246888 Share on other sites More sharing options...
kenrbnsn Posted May 6, 2007 Share Posted May 6, 2007 The OP said he didn't want to pass the string on the URL. Ken Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246892 Share on other sites More sharing options...
HaLo2FrEeEk Posted May 7, 2007 Author Share Posted May 7, 2007 Thank you, ken, I will try that as soon as I have a chance and I will report back. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246909 Share on other sites More sharing options...
HaLo2FrEeEk Posted May 7, 2007 Author Share Posted May 7, 2007 Alright, well, I tried it, I will post the code I am using for my index and vote pages: index.php: <?php define("ck_vote", true); define("ROOT", $_SERVER['DOCUMENT_ROOT'], true); require(ROOT.'/vote/config.php'); // Connecting, selecting database $link = mysql_connect($host, $user, $pass) or die($host_err.mysql_error()."."); mysql_select_db($dbname) or die($db_err.mysql_error()."."); session_start(); switch($_POST['action']) { case "login": if(!empty($_POST['studentID'])) { $_SESSION['studentID'] = $_POST['studentID']; header("Location: vote.php"); } else { echo "Please enter a valid Student ID."; } break; default: echo <<<EOF <form method="POST" /> <input type="password" name="studentID" /> <input type="hidden" name="action" value="login" /> <input type="submit" value="Login" /> </form> EOF; break; } ?> vote.php: <?php define("ck_vote", true); define("ROOT", $_SERVER['DOCUMENT_ROOT'], true); require(ROOT.'/vote/config.php'); // Connecting, selecting database $link = mysql_connect($host, $user, $pass) or die($host_err.mysql_error()."."); mysql_select_db($dbname) or die($db_err.mysql_error()."."); session_start(); $studentID = $_SESSION['studentID']; echo $studentID; ?> I'm trying to keep it simple until I have a better understanding of sessions, am I doing this right? When I click the button in index.php, it takes me to vote.php, but nothing displays, please help. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246951 Share on other sites More sharing options...
HaLo2FrEeEk Posted May 7, 2007 Author Share Posted May 7, 2007 Guys please, I'm usually not one to beg, but I really need help, I cannot get this to work, I've read a lot of pages on google, and all the pages about sessions on php.net, and I cannot get this to work. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246958 Share on other sites More sharing options...
MadTechie Posted May 7, 2007 Share Posted May 7, 2007 make sure you are using session_start(); before using the sessions Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246959 Share on other sites More sharing options...
suttercain Posted May 7, 2007 Share Posted May 7, 2007 Hi Halo Try: <?php session_start(); define("ck_vote", true); define("ROOT", $_SERVER['DOCUMENT_ROOT'], true); require(ROOT.'/vote/config.php'); // Connecting, selecting database $link = mysql_connect($host, $user, $pass) or die($host_err.mysql_error()."."); mysql_select_db($dbname) or die($db_err.mysql_error()."."); $studentID = $_SESSION['studentID']; echo $studentID; ?> I believe session_start(); must be at the top. Report back. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246961 Share on other sites More sharing options...
MadTechie Posted May 7, 2007 Share Posted May 7, 2007 session_start(); must be set before anything is printed to the screen i feel its the header("Location: vote.php"); messing it up.. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246963 Share on other sites More sharing options...
HaLo2FrEeEk Posted May 7, 2007 Author Share Posted May 7, 2007 No go, I tried creating two pages: page1.php: <?php session_start(); $_SESSION['test'] = "test"; echo "<a href=\"page2.php\">Page 2</a>"; ?> page1.php: <?php session_start(); echo $_SESSION['test']; echo "<br /><br /><a href=\"page1.php\">Page 1</a>"; ?> And page2.php didn't echo anything. session.use_cookies is enabled in my php.ini, and here are my other cookie values in php.ini, as reported by phpinfo(): session.cookie_domain no value session.cookie_httponly Off session.cookie_lifetime 0 session.cookie_path / session.cookie_secure Off Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246968 Share on other sites More sharing options...
MadTechie Posted May 7, 2007 Share Posted May 7, 2007 try <?php session_cache_expire(30); session_start(); $_SESSION['test'] = "test"; ?> EDIT: ini_set('session.cookie_lifetime', '30'); may also work OR in you .htaccess. php_value session.gc_maxlifetime 300 php_value session.cookie_lifetime 300 Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246970 Share on other sites More sharing options...
HaLo2FrEeEk Posted May 7, 2007 Author Share Posted May 7, 2007 I might mention that I'm using php 5.2.2 on an apache server running on my home computer, would this affect it at all? I do have access to a webserver though, I will test it there. EDIT: I uploaded the afore mentioned page1.php and page2.php to my webserver, and it worked just fine. The first time I did it, it passed the session ID along with the url, but every other time I've run it, it hasn't. I don't know why it works on my webserver and not my home one, I guess I will have to test it at school to see that it works, or maybe I will use another method, I have one more thing in mind. If anyone can offer any more support, please feel free to, I would much rather use sessions than my alternative fallback, if possible, so any help will be appreciated. Oh, btw, my webserver is running php 4.4.4, my school's vote server is using IIS with php 5.2.0 (I think.) I will test it on it tomorrow. Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246972 Share on other sites More sharing options...
MadTechie Posted May 7, 2007 Share Posted May 7, 2007 you need to edit your php.ini file session.cookie_lifetime session.gc_maxlifetime Quote Link to comment https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/#findComment-246977 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.