Jump to content

Session Token


lanmind

Recommended Posts

Hello everybody,

 

My page: http://www.dockhawk.com/

 

I'm trying to implement some "session security" PHP script

mentioned in the "Cross-site request forgery" section of this

tutorials (pdf): http://daniel0.net/phpfreaks_tutorials/php_security/php_security.pdf

 

I was trying to figure out if it was functioning by putting a value in

the hidden input that won't be equal to the session token. The hidden

input is in my default.html page inside the <div id="search_form">.

 

So as the value is wrong the PHP should return "Invalid Token" but

it's not. In earlier testing I had taken away the not "!" in the PHP

and left the hidden input's value as "<?php echo $_SESSION['token'] ?

 

>" and the PHP did return "Invalid Token" as it should have.

 

It seems the "!" isn't working, I'm not sure. Thank you for your time,

here is the PHP:

 

<?php

 

if ($_GET['token'] !== $_SESSION['token']) {

die('Invalid token');

 

}

 

$keyword=$_GET["name"];

 

require("dockhawk_dbinfo.php");

 

function parseToXML($htmlStr)

{

$xmlStr=str_replace('<','<',$htmlStr);

$xmlStr=str_replace('>','>',$xmlStr);

$xmlStr=str_replace('"','"',$xmlStr);

$xmlStr=str_replace("'",'&#39;',$xmlStr);

$xmlStr=str_replace("&",'&',$xmlStr);

return $xmlStr;

 

}

 

// Opens a connection to a MySQL server

$connection=mysql_connect ($hostname, $username, $password);

if (!$connection) {

  die('Not connected : ' . mysql_error());

 

}

 

// Set the active MySQL database

$db_selected = mysql_select_db($database, $connection);

if (!$db_selected) {

  die ('Can\'t use db : ' . mysql_error());

 

}

 

// Select all the rows in the markers table

$query = "SELECT * FROM markers WHERE MATCH(operator, name, waterway)

AGAINST ('$keyword') LIMIT 0, 25";

$result = mysql_query($query);

if (!$result) {

  die('Invalid query: ' . mysql_error());

 

}

 

header("Content-type: text/xml");

 

// Start XML file, echo parent node

echo '<markers>';

 

// Iterate through the rows, printing XML nodes for each

while ($row = @mysql_fetch_assoc($result)){

  // ADD TO XML DOCUMENT NODE

  echo '<marker ';

  echo 'operator="' . parseToXML($row['operator']) . '" ';

  echo 'name="' . parseToXML($row['name']) . '" ';

  echo 'waterway="' . parseToXML($row['waterway']) . '" ';

  echo 'mile="' . parseToXML($row['mile']) . '" ';

  echo 'address="' . parseToXML($row['address']) . '" ';

  echo 'town="' . parseToXML($row['town']) . '" ';

  echo 'state="' . parseToXML($row['state']) . '" ';

  echo 'lat="' . $row['lat'] . '" ';

  echo 'lng="' . $row['lng'] . '" ';

  echo 'county="' . parseToXML($row['county']) . '" ';

  echo '/>';

 

}

 

// End XML file

echo '</markers>';

 

?>

Link to comment
Share on other sites

Thanks for the fast replies! I'm sorry for not inserting code tags. Dark Water I removed the session_start(); from the PHP file because I assumed it shouldn't have been there. I thought it should have only been on the HTML page.

 

I put it back into the PHP but I'm still having the same issue. The script is continuing even though the value of "token" should not be equal to the session_token. Here is the relevant PHP:

 

<?php

session_start();
if ($_GET['token'] !== $_SESSION['token']) {
die('Invalid token');
}

$keyword=$_GET["name"];

require("dockhawk_...

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.