Jump to content


Photo

SESSIONS Problem!


  • Please log in to reply
27 replies to this topic

#1 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 04:48 AM

First please create these files with the names suggested:

<?php

//inc.php

ob_start();
SESSION_START();
if($_SESSION['user'] == '' || $_SESSION['pswd'] == '')
{
 header("Refresh: 5; URL=login.php");
	   echo "<center>";
	   echo "<BR> You are trying to access a protected area.<BR>".
		   "You are being redirected to Login Page in 5 seconds";
exit;
}
?>

<?php
//main.php

require("inc.php");
include_once "./cmndb.php";
include_once "./pm.php";

echo "<BR>Welcome ".$_SESSION['user']; //doesn't display user's ID????
//SESSIONS NOT WORKING!!!!!

//This is the main page.
//Show user's profile info,
//Private Messages.
//Links to other sections.
?>

<?php

//login.php

ob_start();
SESSOIN_START();


require("cmndb.php");

if($_POST['action']=="authuser")
{	
		
	$uname = authuser($_POST['uid'], $_POST['upswd']);
	

   if($uname==0 OR $uname==1 OR $uname==2)
	 {
		  $PHP_SELF = $_SERVER['PHP_SELF'];

	    echo "<h1>Authorization failed.</h1> ";
       if($uname==2)
	      {
			echo "<BR>Ooops! Your account isn't verified as of yet.<BR>".
			        "<A HREF=\"verify.php\">Click Here</A> to verify your email address.<BR>".
                                                  "If you haevn't recieved any Verification email <A HREF=\"sendvcode.php\">Click 

here</A><BR>";
			exit;
			}
		else if($uname==0) echo "<BR>Ooops! Your provided UserID doesn't even exits!<BR>" ;

		else	echo "<BR>Ooops! Your password isn't correct!<BR>";

	 	echo "Click on the following link to try again.<BR>\n";
      echo "<A HREF=\"$PHP_SELF\">Login</A><BR>";
      echo "If you're not a member yet, click " .
           "on the following link to register.<BR>\n";
      echo "<A HREF=\"$register_script\">Membership</A>";
      exit;



   }
   else
	{
	   
	   $user=$_POST['uid'];
	   $pswd=$_POST['upswd'];
	   $_SESSION['log']=1;
	   $_SESSION['user']=$user;
	   $_SESSION['pswd']=$pswd;
	   header("Location: main.php");/*
	   echo "<center> Welcome back ";
	   echo $_SESSION['user']."<BR> Please wait while you are redirected.<BR>".
		   "You are being redirected to Homepage in 5 seconds";*/
       exit;
	  }
	  
}

?>
<FORM METHOD="POST" ACTION="<?php echo $PHP_SELF ?>">
   <DIV ALIGN="CENTER"><CENTER>
<input type="hidden" name="action" value="authuser">
      <H3>Please log in to access the page you requested.</H3>
   <TABLE BORDER="1" WIDTH="200" CELLPADDING="2">
      <TR>
         <TH WIDTH="18%" ALIGN="RIGHT" NOWRAP>ID</TH>
         <TD WIDTH="82%" NOWRAP>
            <INPUT TYPE="TEXT" NAME="uid" SIZE="8">
         </TD>
      </TR>
      <TR>
         <TH WIDTH="18%" ALIGN="RIGHT" NOWRAP>Password</TH>
         <TD WIDTH="82%" NOWRAP>
            <INPUT TYPE="PASSWORD" NAME="upswd" SIZE="15">
         </TD>
      </TR>
      <TR>
         <TD WIDTH="100%" COLSPAN="2" ALIGN="CENTER" NOWRAP>
            <INPUT TYPE="SUBMIT" VALUE="LOGIN">
         </TD>
      </TR>
   </TABLE>
   </CENTER></DIV>
</FORM>
<center>
<font face="Tahoma" size="2" color="Black"><A HREF="forgotpassword.php">Forgot UserID/Password? </A> 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<A HREF="register.php">New? </A><BR>
	<A HREF="sendvcode.php">Haven't Recieved Verification Email? </A></font></center>
<?php

function authuser($uid, $upswd) {
   global $user_tablename;

	dbconnect();
	$query = "SELECT * FROM $user_tablename
                             WHERE uid = '$uid'";
   $result = mysql_query($query);


  if(!mysql_num_rows($result)) return 0;
  else
  {
	  $arr=mysql_fetch_array($result);
	   if($upswd!=$arr['upswd']) return 1;
	  else if ($arr['ustat']==0) return 2;
	  else return 5;

	}
}
?>




Here sessions aren't working. I have my register_globals set to off, have provided a valid path and all other settings. So any idea what the problem is????



#2 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 02 August 2006 - 04:51 AM

try taking the "exit;" out.. I have a site that does the same thing, but i don't ever use exit;
I could be wrong, considering Im not a pro, but I think Im right
Link shortener with advanced, detailed statistics:

http://tyny.us/

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:06 AM

first thing session_start(); is lower case ok.

and secondly you alredy got header problams becouse you use ob_start(); maybe its a good idear to sort that as well ok.?


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 05:31 AM

Well somethings:
1st that i don't think removing exit; will do a change, still i will try.
And then about lowercase and uppercase, well tell you what its correct both ways SESSION_START(); and session_start() do the same thing. and then about ob_start(), well its just something i added as a precaution so that if i accidently pass any code before the session_start(), the error "headers already sent" may not occur, i also tried by removing the ob_start() but still doens't make any change, used different browsers, but all in vain...

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:36 AM

do a session test then

test.php
<?php session_start();
$name="my name is redarrow";
$name=$_SESSION['name'];

echo"<a href='test_result.php'>test me</a>";
?>
test_result.php
<?php session_start();
echo $name;
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 05:40 AM

do a session test then

test.php

<?php session_start();
$name="my name is redarrow";
$name=$_SESSION['name'];

echo"<a href='test_result.php'>test me</a>";
?>
test_result.php
<?php session_start();
echo $name;
?>


Well to tell the truth i did this, on the first page its displayed crystal clear but its null on second. i even used to check it using isset() and strlen but both return false.

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:46 AM

sorry

$name=$_SESSION['name']=$name;
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 05:47 AM

sorry

$name=$_SESSION['name']=$name;

nope, i knew that you meant it that way......
its just as i said, that name is asked would be display on the first page but on the second its null.

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:48 AM

test_result.php
<?php session_start();
echo $name;
?>

test.php
<?php session_start();
$name="my name is redarrow";
$name=$_SESSION['name']=$name;

echo"<a href='test_result.php'>test me</a>";
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:49 AM

on the first page should only get the link
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:52 AM

your session must be off in the php.ini then thats all i can think off.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 05:55 AM

test_result.php
<?php session_start();
echo $name;
?>

test.php
<?php session_start();
$name="my name is redarrow";
$name=$_SESSION['name']=$name;

echo"<a href='test_result.php'>test me</a>";
?>

First that read the comments 

In the first code segment i.e. test_results, $name? shouldn't it be $_SESSION['name'] as $name isn't transferred, only thing lives is session

Secondly i said that if we echo out the name in test, its displayed but not in the test_result (even by using $_SESSION['name']

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 06:25 AM

every page got to have the <? session_start(); on it.


where the name form the form name=""

<INPUT TYPE="SUBMIT" VALUE="LOGIN">

PHP_SELF// get rid off it use the proper way or no way.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:26 AM

every page got to have the <? session_start(); on it.

as you can see the code segments that i attached in the first post do have that, don't they?

#15 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 06:31 AM

main has not got it.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#16 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:32 AM

main has not got it.

main has included the inc.php thus it also have got it. and evne if i write, nothing much happens as the code as soon as it read the inc.php it gets redirected to the login page as there isn't any session that exists while inc.php

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 06:34 AM

what in these then

require("inc.php");
include_once "./cmndb.php";
include_once "./pm.php";

somethink must be dragging it down.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:35 AM

what in these then

require("inc.php");
include_once "./cmndb.php";
include_once "./pm.php";

somethink must be dragging it down.

cmndb is a file as the name points common database, it gives connects to database for the profile information retrieval, and pm.php is a file containg function to read pm, delete, compose and etc... nothing much, even tried deleting these files or commenting these lines of code,

#19 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 06:38 AM

very anoying and i am sitting here.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#20 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 06:42 AM

what about using POST['varable_names'];


what instead of useing the session['what_ever']=$whatever

maybe you should use session_register($whatever); then $_POST['what_ever'];

i am stomped.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users