Challenge for php guru - this is making my head ache!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

just assign it a username like this...

Code: Select all

$_SESSION['username'] = 'n00b Saibot';

Feyd! are you pleased now... :wink:
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Ok my head really is ready to explode. Maybe it is just easier if I post my code:

Code: Select all

<?
session_start(); 
session_register ("username"); 
?>

<html>

<?

require 'user_routines.php';
require 'booking_routines.php';

$acc=$_GET["acc"];
$function=$_GET["function"];
$submit=$_GET["submit"];

if (isset($_POST['submit']) || $submit==1){

     if(!$username){
	$username=$_POST["username"];
                   }
     else{
        	$username=$HTTP_SESSION_VARS["username"];
         }

     $username=strtoupper($username);

     echo"Test variable: $username";
                        
else{

     ?>
     <form method="POST" action="<? $PHP_SELF; ?>">
     <p class="bodytext">Please input your Account No. below to log-in to our system.</p>
     <p class=bodytext><input type="text" size="15" name="username"></p>
     <input class=button type="submit" value="Submit" name="submit"></p>
     </form>
     <?	

    }

?>

</body>
</html>
The variable 'username' outputs the correct value when this condition is met:

Code: Select all

if(!$username){
	$username=$_POST["username"];
But not when this condition is met:

Code: Select all

else{
        	$username=$HTTP_SESSION_VARS["username"];
    }
It seems the session variables are not working?

Rob.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

Thanks for the help I now have it working I think!

Here is how I did it......

Code: Select all

<?
session_start(); 
session_register ("username"); 
?>

$flag=$_GET["flag"];
$function=$_GET["function"];
$submit=$_GET["submit"];
$job_num=$_GET["job_num"];

if (isset($_POST['submit']) || $flag==1){

    if($flag==1){
         $username=$HTTP_SESSION_VARS["username"];
                }
    else{
	$username=$_POST["username"];
        }

    $HTTP_SESSION_VARS["username"]=$_POST["username"];
'flag' is a variable passed from the left handside navigation with value=1. So I am saying if the link is called from the lefthand side navigation menu then read the username from the pre-assigned session variable value. Else, if the page has been called via the log-in form read the value from the POST form data.

Now this is working nicely but I receive this message once I click an option from the lefthand side menu which is relying upon the session data:

Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

Rob.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

I removed line 19 and it seems to have done the trick, removing the warning message - which is great!

Thanks all of your help!
Post Reply