Jump to content

a href in a form to set session


SirChick

Recommended Posts

How do check if a "<h ref " link was clicked in a process page for example

 

i got the form tags then <a href="test.php">test</a>

 

and the form action goes to formprocess. so i want to do an "isset" on the test.php ahref so i can set a session for it .....

 

can that be done ? or can it only be done with submit buttons and check boxes etc?

Link to comment
Share on other sites

argh wait i cant use get... the idea of session creation was to stop some one linking to the process page without the form's input...

 

so was going to do like:

 

if isset set $session == yes

 

then

 

if session != yes header to what ever page.

 

if i use get it is exploitable :P

 

 

would you know any other idea that may work with what i am thinking of ?

Link to comment
Share on other sites

A hidden form is not hidden with security in mind. It is to pass arguments to the processing page that do not require user input. Once the form is in your browser, a quick check of the source will reveal the hidden field(s) and the values assigned.

 

The only way to do this with any sense of security is to dynamically change the hidden input's value. The value is stored in MySQL, then when the form is submitted, the value is checked against the DB. Remove old values, create new ones as necessary. Sort of a poor man's captcha for form submission.

 

PhREEEk

Link to comment
Share on other sites

I think this is what your trying to do....

 

form.php

<?php

  session_start();
  $_SESSION['valid'] = true;

?>
<form action='process.php' method='post'>
  <input type='text' name='foo'>
  <input type='submit' name='submit'>
</form>

 

process.php

<?php

  session_start();
  if (isset($_POST['submit'] && isset($_SESSION['valid'])) {
    unset($_SESSION['valid']);
    // process form.
  }

?>

Link to comment
Share on other sites

problem with that is... say the user views the form... then goes to do other stuff then changes the url to process.php itll still process cos session hasnt unset. =/

 

im trying to find a way that the session is created upon for post has started and so when do activate the form there is no go back anyway

Link to comment
Share on other sites

A simple solution to that is to simply store the current page (do this on every page) in the $_SESSION array on each request.

 

form.php

<?php session_start(); ?>
<form action='process.php' method='post'>
  <input type='text' name='foo'>
  <input type='submit' name='submit'>
</form>
<?php
  // This needs to be the last line of every page in your site.
  // or prior to any redirecting.
  $_SESSION['referer'] = $_SERVER['SCRIPT_NAME'];

?>

 

process.php

<?php

  session_start();
  if (isset($_POST['submit'] && $_SESSION['referer'] == 'form.php')) {
    unset($_SESSION['valid']);
    // process form.
  }

  $_SESSION['referer'] = $_SERVER['SCRIPT_NAME'];

?>

 

There are many ways to get this done.

Link to comment
Share on other sites

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.