Help - Search - Members - Calendar
Full Version: Session_start()
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Paul L
Hi,

I'm having trouble running a standard script which has been around years, and works on other servers.

Turns out that the problem is with the variable $_SESSION['captcha_id']

The code in index.php starts:
CODE
<?php
// Make the page validate
ini_set('session.use_trans_sid', '0');
// Include the random string file
require 'rand.php';
// Begin the session
session_start();
// Set the session contents
$_SESSION['captcha_id'] = $str;
etc.

and then it calls another routine which starts:
CODE
<?php
// Begin the session
session_start();
// If the session is not present, set the variable to an error message
if(!isset($_SESSION['captcha_id']))
$str = 'ERROR!';
etc.


and I get the error message. So for some reason, the $_SESSION['captcha_id'] variable isn't crossing to the second routine (I've double checked this). Can anyone give me a hint as to why? Is there anything else I need to do or maybe there's a php setup option that I'm not aware of? I'm really lost!

The original code is at http://psyrens.com/captcha/captcha.rar if you're interested.

The second piece of code is called image.jpg.

Any help would be appreciated.

Thanks,

Paul
Jetteh22
I'm not sure what you're doing wrong.. It seems to work fine for me:
http://www.thinkcreactive.com/test2.php

test2.php = your index.php
CODE
<?php

// Include the random string file
require 'test.php';

// Begin the session
session_start();

// Set the session contents
$_SESSION['captcha_id'] = $str;

if(!isset($_SESSION['captcha_id']))
$str = 'ERROR!';

echo $str;
?>


test.php in that block is the same as your rand.php, no editing at all.. It works fine for me.
Paul L
Thanks for the reply Jetteh22.

Does anyone know of something that will stop the session_start() from working? A php variable or similar?

Getting desperate!

Paul
Ed
What's the error, always helpful in helping debug issues like this.

Also try adding some additional error reporting:

CODE
error_reporting(E_ALL);
ini_set('display_errors', true);


If this is hosted on Zymic's hosting, ini_set is disabled so just comment out that line.
MindFreak
Paul L, you should not create php files at Notepad, because it adds BOM symbols at the beginning of the file which causes printing content before session starts, as you know, this is not allowed ;]
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.