Jump to content

Using Sessions


lanmind

Recommended Posts

Hello everybody,

 

On my page here: http://www.dockhawk.com/

I referenced this article: http://phpsec.org/projects/guide/2.html

 

I'm using a session variable to ensure a query sent to my database actually comes from my site. Problem is is that if you type something like: http://www.dockhawk.com/currentphp.php?name=houston into a URL bar data as valid XML is being returned.

 

I'm assigning the session value to a javascript variable and sending it to the PHP inside the javascript function "getmarks();" using AJAX. The PHP queries the db then returns a new session value in XML to ensure each session var is used only once. The session value is then reassigned to the javascript var for the next query. Here is the relevant PHP:

 

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

$_SESSION['token'] = uniqid(md5(microtime()), true);

$coin = $_SESSION['token'];

...

 

I was hoping using sessions would ensure my data could only be queried from my page. Any ideas why this doesn't work?

 

Thank you.

Link to comment
Share on other sites

@iversonm:

 

$a != $b  Not equal  TRUE if $a is not equal to $b.

$a !== $b  Not identical  TRUE if $a is not equal to $b, or they are not of the same type. (introduced in PHP 4)

 

In both cases he will get the same result in his if function, because it's the same type.

 

Although, as looking now if

$_SESSION['token'] = uniqid(md5(microtime()), true);

is encoded with md5. Then

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

is always FALSE unless decoded.

 

@lanmind:

 

Where do you get

$_SESSION['token']

for your if statment

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

?

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.