Jump to content

Archived

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

shoaibi

SESSIONS Problem!

Recommended Posts

First please create these files with the names suggested:

[Code]
<?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;

}
}
?>
[/Code]




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????

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
do a session test then

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

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

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407821#msg407821 date=1154496994]
do a session test then

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

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

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.

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407831#msg407831 date=1154497571]
sorry

$name=$_SESSION['name']=$name;
[/quote]
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.

Share this post


Link to post
Share on other sites
[code]
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>";
?>
[/code]

Share this post


Link to post
Share on other sites
your session must be off in the php.ini then thats all i can think off.

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407836#msg407836 date=1154497713]
[code]
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
[/code]
[/quote]
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']

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407850#msg407850 date=1154499915]
every page got to have the <? session_start(); on it.
[/quote]
as you can see the code segments that i attached in the first post do have that, don't they?

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407852#msg407852 date=1154500267]
main has not got it.
[/quote]
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

Share this post


Link to post
Share on other sites
what in these then

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

somethink must be dragging it down.

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407854#msg407854 date=1154500446]
what in these then

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

somethink must be dragging it down.
[/quote]
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,

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=redarrow link=topic=102670.msg407861#msg407861 date=1154500935]
what about using POST['varable_names'];
[/quote]
sorry redarrow but if i had to come back to the POST and why did i used sessions, the only thing i wanted was that more secure, more reliable. and also easy, POST won't be easy as i don't thing except then the form you cna use POST to transfer information from one place to other.

Share this post


Link to post
Share on other sites
[quote]//login.php

ob_start();
SESSOIN_START();[/quote]
I think the misspelling of SESSION_START() might have something to do with it.

Share this post


Link to post
Share on other sites
[quote author=mastermike707 link=topic=102670.msg407874#msg407874 date=1154501497]
[quote]//login.php

ob_start();
SESSOIN_START();[/quote]
I think the misspelling of SESSION_START() might have something to do with it.
[/quote]
That's the problem you found here, but in the actuall code its not.... ;)

Share this post


Link to post
Share on other sites

×

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.