Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2003, 04:21 AM
Registered User
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c_capo
Default Session problem (yet another one)

I have a problem with my sessions. I will explain by adding some code:

index.php: (this works fine)

<?php
  if (do_enter){
    session.start()
    $_SESSION("granted") = "yes";

    header("Location: admin.php");
    exit;
  }
  else{
    // do something else
  }
?>


admin.php:

<?php
  if($_SESSION("granted")<>"yes"){
    header("Location: admin.php");
    exit;
  }
  else{
    //whatever I want to do on this page
  }
?>


If I try to login on my index page, he goes to admin.php
but admin.php sends the user back to index.php (I tested this).
Is there something wrong with my script or my sessions??

Help appreciated

:: soulcreation.com ::
 
Old October 2nd, 2003, 04:33 AM
Registered User
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c_capo
Default

Mistake in my script I posted:

I use session_start(); //in case someone is going to
                        //say something about this


Claudio

:: soulcreation.com ::
 
Old October 2nd, 2003, 03:08 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi c_capo

You need to use braces to form your arrays and not parenthesis.

$_SESSION["granted"];

http://www.php.net/manual/en/language.types.array.php

: )

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old October 2nd, 2003, 06:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You say that you use session_start in your script... I just want to clarify, since you're missing it in admin.php.

Also, your admin.php seems quirky: when $_SESSION['granted'] is NOT equal to "yes", you're redirected back to admin.php, not index.php... Is this a typo in your post, or a bug in your actual code?

A complete working version follows:


<?php // index.php

if (isset($_GET['do_enter']) && ($_GET['do_enter'] != ''))
{
    session.start()
    $_SESSION['granted'] = 'yes';

    header('Location: admin.php');
    exit;
}
else
{
    // do something else
}
?>


<?php // admin.php

session_start();

if ($_SESSION['granted'] !== 'yes')
{
    header("Location: index.php");
    exit;
}
else
{
    //whatever I want to do on this page
}
?>


To enter the admin site, just append "?do_enter=true" to the URL after index.php.


Take care,

Nik
http://www.bigaction.org/
 
Old October 12th, 2003, 05:05 PM
Authorized User
 
Join Date: Aug 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is your configuration (exactly what web server do you use) ?
That might also help.
E.g :
- with apache, you don't have to send the sid (session id) to every page through links and forms
- with iis, you have to explicitely retrieve the sid in every page, sent as a GET or as a POST.
So if you use IIS, since you don't send the sid, it's completely normal that you're redirected as not logged in.

php/java developer
NTIC engineer
 
Old October 16th, 2003, 01:34 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi

if you are testing your page on IE try to check te security level setting.
If setted to high, change it to medium



 
Old October 17th, 2003, 06:24 AM
Registered User
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c_capo
Default

I have found this:
http://bugs.php.net/bug.php?id=14636


Seems the problem is with HTTP.
I might use cookies but prefer sessions above cookies.

Claudio

:: soulcreation.com ::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Out Problem kasipandian J2EE 3 March 21st, 2008 03:35 PM
session problem MunishBhatia ASP.NET 2.0 Professional 9 October 6th, 2007 04:06 AM
Session problem abdulweb General .NET 3 August 27th, 2007 08:01 PM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.