Session problem, help Pejone!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Session problem, help Pejone!

Postby ruturajv » Sat Jun 28, 2003 9:26 pm

I am using sessions, and I redirect the from the login page to the main page if the user is registered. But I have a problem sometimes I can't log the user, so instead of redirecting the user using header('location: location.php'), I write a META tag and then redirect and give the page some time to create a session about 2 seconds. But still the problem does persist, And this happens only during the first time. Later everything works fine. And in the first time when i append the 'SID' to the page, The page url shows

location.phpPHPSESSID=5a8241c53dd904f3c16e31ab48798387

appended to the file. and then I get 404 error, If i remove the PHPSESSID part, The page works as expected, But for the first time why does it show on the URL? which causes error.

I think Pejone or some Moderator had written about this, and that is the reason I redirect using meta tag, but still...

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Sun Jun 29, 2003 8:05 pm

It would help to see some code on your session registration.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Here is the code!!

Postby ruturajv » Mon Jun 30, 2003 5:40 am

Code: Select all

<?php

//Write the function to write the meta tag for redirection
function write_meta($location)
{
   echo ("<html><head>");
   echo ("<title>You are being redirected</title>");
   echo ("<link rel=stylesheet type='text/css' href='style.css'>");
   echo ("<meta http-equiv=\"refresh\" content=\"2;url=" . $location . "\">");
   echo ("<div align=center>");
   echo ("The page is being redirected. ");
   echo ("If your browser doesn't support meta redirection, <a href=\"" . $location . "\">Click here</a>" . "</div><br>");
   echo ("</head></html>" . "<br>");
}

if (($_POST['username'] == "") || ($_POST['password'] == "")) {
   write_meta("fault.sps?err=nothing");
   exit;
}

include ('connect.sps');

//get post variables
$username = $_POST['username'];
$password = $_POST['password'];

//function for administrator
function check_admin($user)
{
   if (strcmp($user, "ruturajv") == 0) { //using string comparision
      return true;
   }else {
      return false;
   }
}

if(isset($username) && isset($password)) {
   //write sql
   $sql = "select memberid, username, password from members where username='" .  $username. "';";

   $result = mysql_query($sql, $conn);
   $row = mysql_fetch_assoc($result);
   
   //test query
   $success = false;
   

   if ((strcmp($row['username'], $username) == 0) && (strcmp($row['password'], $password) == 0)) {
      $success = true;
   } else {
      mysql_close($conn);
      write_meta("fault.sps?err=userpassinc");
      exit;
   }
   
   //check for administrator
   if ($success) {
      $admin = check_admin($username);
   }
   

   //nowset the session variable
   session_register('auth');
   $_SESSION['auth'] = true;
   session_register('username');
   $_SESSION['username'] = $username;
   session_register('memberid');
   $_SESSION['memberid'] = $row['memberid'];
   session_register('admin');

   if ($admin) {
      $_SESSION['admin'] = true;
   }else {
      $_SESSION['admin'] = false;
   }

   //send the user to authorized page
   $mainpage = 'main.sps' . SID;
   write_meta($mainpage);
   
   //close the mysql connection
   mysql_close($conn);

} else {
   write_meta("fault.sps?err=userpass");

   //close the mysql connection
   mysql_close($conn);

}

?>

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

help

Postby ruturajv » Tue Jul 01, 2003 8:25 am

Hello,
I've posted the code , can anybody reply to my problem..
:cry:

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Tue Jul 01, 2003 3:30 pm

Do you realise your link should be...

file.php?phpsessid=5684dsa6f51sdx6g41fds6g

Note the question mark.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Pejone, or some moderator help!!!

Postby ruturajv » Wed Jul 02, 2003 12:33 am

My problem is not that ? will make a query string, but i want to pass the SID variable transperently as it goes in PHP

i don't want it to be visible.. otherwise '?' would be used to querystring appending

Pe

phPMaster
New php-forum User
New php-forum User
Posts: 4
Joined: Wed Jul 02, 2003 2:23 am

Probably a solution

Postby phPMaster » Wed Jul 02, 2003 2:49 am

You can try the following solution:

header('location:location.php?PHPSESSID=5a8241c53dd904f3c16e31ab48798387')

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Wed Jul 02, 2003 7:53 pm

Here is all about that from the php manual.
Passing the Session ID
There are two methods to propagate a session id:


Cookies

URL parameter


The session module supports both methods. Cookies are optimal, but because they are not always available, we also provide an alternative way. The second method embeds the session id directly into URLs.

PHP is capable of transforming links transparently. Unless you are using PHP 4.2 or later, you need to enable it manually when building PHP. Under UNIX, pass --enable-trans-sid to configure. If this build option and the run-time option session.use_trans_sid are enabled, relative URIs will be changed to contain the session id automatically.

Note: The arg_separator.output php.ini directive allows to customize the argument seperator. For full XHTML conformance, specify & there.


Alternatively, you can use the constant SID which is always defined. If the client did not send an appropriate session cookie, it has the form session_name=session_id. Otherwise, it expands to an empty string. Thus, you can embed it unconditionally into URLs.



I thought you were trying to pass the session ID.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Yess..

Postby ruturajv » Fri Jul 04, 2003 5:48 am

I have enabled transperent session passing in the url

However, when logining for the first time, the code genereates the PHPSSID=and the crap, however later during other sign-in , this does not occur!!!

:cry: :cry:


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests