Jump to content

Apparently braindead newbie


petermholmes

Recommended Posts

I'm a newbie to PHP and can't figure out what's wrong with the following:

 

File tryme.php contents:

 

<?php require("session/session_check.php"); ?>

<form method="post" action="./php/trymecall.php">
  Email: <input name="email" type="text" /><br />
  Message:<br />
  <textarea name="message" rows="15" cols="40">
  </textarea><br />
  <input type="submit" />
</form>

 

File session_check.php contents:

 

<?php
  /* session_check - attempt to keep our sessions secure */

  if (!isset(session_id()))
  {
    /* setup a new session */

    session_start();
    $_SESSION['uniqid'] = uniqid('', true);
    $_SESSION['key'] = hash('sha256', $_SESSION['uniqid'] . session_id());
  }
  else if ($_SESSION['key'] != hash('sha256', $_SESSION['uniqid'] . session_id()))
  {
    /* huh? */

    echo "Don't mess with me suckah!";
  }
  else
  {
    /* pick up where we left off */

    session_start();
  }
?>

 

When I try to load tryme.php, I get "Fatal error: Can't use function return value in write context in /var/www/session/session_check.php on line 4"

 

Write context???  What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/189815-apparently-braindead-newbie/
Share on other sites

Move the session_start() under the php start tag.

and just what the error says

if (!isset(session_id()))

sessionid() is taken as a function, it is but its session_id() and cant be used in that context.

try:

 

<?php

session_start();

$session_id = session_id();

if (!isset($session_id))

{whatever}

 

 

HTH

Teamatomic

 

<?php
session_start();
$session_id = session_id();
if (!isset($session_id))
{whatever}

 

I don't think that that would accomplish what I was trying to do which was to use isset(session_id()) to determine if a session was already running.  The idea was:

 

1. If no session's running, start one.

2.  If a session already exists but the session key is wrong, somebody's probably trying to break in.

3. If a session exists and the key is good, just pick up the current session variables.

 

Is there another way to accomplish that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.