PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 7th, 2005, 07:32 PM
acb460acb acb460acb is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 1 acb460acb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 52 sec
Reputation Power: 0
Simple?? Problem with php sessions.

I am kind of new to PHP sessions but I cant seem to pass a simple variable form page to page? Here are my two scripts, labled page1 and page 2

Page1---------
PHP Code:
<?php
session_start
(); 
session_register("valid");  
$_SESSION['password'] = $_POST['password'];
if(
$_SESSION['password']==****||$_SESSION['password']==***** || $_SESSION['password']==*****){
header("Location: http://www.islandtrees.org/main/*****/");
$_SESSION['valid'] = 'yes';
}else{
header("Location: http://www.islandtrees.org/main/login.php");
}
?>


Then the file that is fowarded to if the password is correct is

PHP Code:
<? 
if( $_SESSION['valid'] == 'yes'){
echo 
valid;
}else{
echo 
notvalid;
}
include 
'http://www.islandtrees.org/main/header.html'
?>


On the second script the session is opened earlier in the page... I am getting neither valid nor not valid on the second page... any tips?

Reply With Quote
  #2  
Old October 8th, 2005, 04:20 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
You should call session_start() before reading $_SESSION[..] in the second file.. In the first file you should put $_SESSION['valid']='yes' before the header('') statement.

Reply With Quote
  #3  
Old October 8th, 2005, 04:22 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
Didn't catch the last line of your post. You are already starting the session somewhere earlier so that's not it.. Putting $_SESSION=.. before the header should fix it though.. Unless you use output buffering the header command will redirect your page before the session variable is set.
Comments on this post
Itsacon agrees: Right, as usual...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Simple?? Problem with php sessions.


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap