Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/50289-passing-post-information-without-a-form/
Share on other sites

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

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.

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.

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 

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

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.

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.