0

can anyone see where i am not reciving the results I am looking for ?
please,

?><META name=GENERATOR content="MSHTML 8.00.7600.16722"><?session_start();if(!session_is_registered(myusername)){header("location:main_login.php");
   }
   ?>
   <P>

    <? echo "PLAYER:" .'($myusername)';?>

this code is spose to echo out the players login name from the check_login.php page from before.
thanks.

4
Contributors
16
Replies
17
Views
6 Years
Discussion Span
Last Post by Kniggles
Featured Replies
  • 1
    diafol 3,720   6 Years Ago

    As diet says: [ICODE]$_SESSION(myusername)[/ICODE] should be [ICODE]$_SESSION['myusername'][/ICODE] When you were using [ICODE]session_is_registered[myusername][/ICODE] should have been [ICODE]session_is_registered("myusername")[/ICODE] As for getting bits from all over and not knowing what you're doing. PLEASE, get a downloadable copy of the php manual from the php.net site. It'll save you (and possibly others) a lot … Read More

0

What output are you actually getting? Some of that code is deprecated but what stood out to my eye was '($myusername)' which given the username of 'Bob':

What you expect:
PLAYER: (Bob)

What you'd get:
PLAYER: ($myusername)

Reason being that using single quotes prevents PHP from substituting the variable's contents in the output, using double quotes there would fix that.

The other thing is that I'd probably replace !session_is_registered(myusername) with !$_SESSION[myusername] just for yucks.

Edited by dietdew12z: n/a

0

What output are you actually getting? Some of that code is deprecated but what stood out to my eye was '($myusername)' which given the username of 'Bob':

What you expect:
PLAYER: (Bob)

What you'd get:
PLAYER: ($myusername)

Reason being that using single quotes prevents PHP from substituting the variable's contents in the output, using double quotes there would fix that.

The other thing is that I'd probably replace !session_is_registered(myusername) with !$_SESSION[myusername] just for yucks.

Hi dietdew12z, thanks for helpping,

the output i am getting with the above code,

echo "Player: ".($myusernam) Login Successful

the output I am looking for is

Player Bob Login Successful.

0
?>

<META name=GENERATOR content="MSHTML 8.00.7600.16722">

<?php
session_start();
if(!SESSION[myusername])
  {
  header("location:main_login.php");
  }
?>
   <p>

<?php

 echo "PLAYER: $myusername ";

?>

  </p>

See if this doesn't work a little better.

0
<HTML><HEAD><TITLE></TITLE>
<META name=GENERATOR content="MSHTML 8.00.7600.16722">
<?session_start();if(!session_is_registered[myusername]){header("location:main_login.php");}?><P>
 
<? echo "Player: "."($myusername)"  
Login Successful</P><P>&nbsp;</P><P><A href="../logout.php" target=_self>Log out </A>

this code gives me the output

Parse error: syntax error, unexpected '[' in /home/abc123/public_html/login_success.php on line 1
0
<html><head><title></title>
<meta name=GENERATOR content="MSHTML 8.00.7600.16722">
<?php session_start();if(!$_SESSION[myusername]){header("location:main_login.php");} ?><p>
 
<?php echo "Player: "."($myusername)"; ?>
Login Successful</p><p>&nbsp;</p><p><a href="../logout.php" target=_self>Log out </a>

Okay, try this. :)

The error you saw above was because I substituted a system global variable $_SESSION[] for your PHP function session_is_registered() and one wants brackets, the other wants parenthesis.

I still think, though, that you should close your <head> before echoing the player login to the page. So maybe:

<html><head><title></title>
<meta name=GENERATOR content="MSHTML 8.00.7600.16722">
<?php session_start();if(!$_SESSION[myusername]){header("location:main_login.php");} ?>
</head><body>
<p>
 
<?php echo "Player: "."($myusername)"; ?>
Login Successful</p><p>&nbsp;</p><p><a href="../logout.php" target=_self>Log out </a>
</body>

This might work better in the long run.

Edited by dietdew12z: n/a

0

Place session_start() right at the top of the page. header() won't work once you output html or anything else to the page.
Use long tags (<?php instead of <?).
Your HTML looks a little dated. Are you using Word or something?
Where is $myusername being initialised? It doesn't seem to exist, but you're echoing it out.

session_is_registered[myusername]

That's suspect. It waffles on about '['. Looks like your culprit. You should use normal brackets. Perhaps you shouldn't use session_is_registered anyway:

http://php.net/manual/en/function.session-is-registered.php

Sorry Kniggles, but this is a bit of a mess.

0
?>

<META name=GENERATOR content="MSHTML 8.00.7600.16722">

<?php
session_start();
if(!SESSION[myusername])
  {
  header("location:main_login.php");
  }
?>
   <p>

<?php

 echo "PLAYER: $myusername ";

?>

  </p>

See if this doesn't work a little better.

Parse error: syntax error, unexpected '[' in /home/a4393300/public_html/login_success.php on line 5

:(

0

Give this a try:

echo "Player: (".$myusername.") Login Successful"

Hi jrotunda85,
thanks for helping your code give me the output

?>

echo "Player: (".$myusername.") Login Successful" Login Successful

:(

0
<html><head><title></title>
<meta name=GENERATOR content="MSHTML 8.00.7600.16722">
<?php session_start();if(!$_SESSION[myusername]){header("location:main_login.php");} ?><p>
 
<?php echo "Player: "."($myusername)"; ?>
Login Successful</p><p>&nbsp;</p><p><a href="../logout.php" target=_self>Log out </a>

Okay, try this. :)

The error you saw above was because I substituted a system global variable $_SESSION[] for your PHP function session_is_registered() and one wants brackets, the other wants parenthesis.

I still think, though, that you should close your <head> before echoing the player login to the page. So maybe:

<html><head><title></title>
<meta name=GENERATOR content="MSHTML 8.00.7600.16722">
<?php session_start();if(!$_SESSION[myusername]){header("location:main_login.php");} ?>
</head><body>
<p>
 
<?php echo "Player: "."($myusername)"; ?>
Login Successful</p><p>&nbsp;</p><p><a href="../logout.php" target=_self>Log out </a>
</body>

This might work better in the long run.

Player: ()Login Successful

 

Log out

used the 2nd eg. thanks for the close heads tag :)

0

Place session_start() right at the top of the page. header() won't work once you output html or anything else to the page.
Use long tags (<?php instead of <?).
Your HTML looks a little dated. Are you using Word or something?
Where is $myusername being initialised? It doesn't seem to exist, but you're echoing it out.

session_is_registered[myusername]

That's suspect. It waffles on about '['. Looks like your culprit. You should use normal brackets. Perhaps you shouldn't use session_is_registered anyway:

http://php.net/manual/en/function.session-is-registered.php

Sorry Kniggles, but this is a bit of a mess.

ardav, thanks for your pointers, am finding bits of code all over the net , dont realy quite no what i am doing , just know its fun to play about with computers.
the place where i am at is that players turn up to screen1 and enter name password, then it gos to check_login.php and if right they turn up in login_success.php with there players namebadge.

0

am now upto

<?php session_start();
$myusername = ($_SESSION(myusername);
if(!$_SESSION(myusername)){header("location:main_login.php");} ?>
  <html><head><title></title>
<meta name=GENERATOR content="MSHTML 8.00.7600.16722">
</head><body>
<p>
 
<?php echo "Player: "."($myusername)"; ?>
Login Successful</p><p>&nbsp;</p><p><a href="../logout.php" target=_self>Log out </a>

with ouput:

Parse error: syntax error, unexpected ';' in /home/a4393300/public_html/login_success.php on line 2

0

First, instead of going to different places on the web and gleaning bits of code you'd be better served going to www.w3schools.com, if you haven't already, and going through their PHP tutorial. It's easy, quick and will give you a good basic understanding of PHP. You'll find very few people here who haven't used w3schools at one time or another.

$_SESSION is a variable array that holds your session data, since it's an array use use [ and ] to specify which value you are wanting. In this case it's myusername so you access the session variable by using $_SESSION[myusername]. In PHP functions you use parenthesis so if you wanted to unset that variable you'd use the function unset($_SESSION[myusername]);

So a function uses ( and ) but a variable array uses [ and ].

Also in line 2, which you probably caught already, you have an extra parenthesis right after the equals. Parentheses always come in pairs so if you count the number of parenthesis it should always be an even number. The number one problem I have when coding is lop-sided parentheses and lop-sided braces.

David

1

As diet says: $_SESSION(myusername) should be $_SESSION['myusername'] When you were using session_is_registered[myusername] should have been session_is_registered("myusername") As for getting bits from all over and not knowing what you're doing. PLEASE, get a downloadable copy of the php manual from the php.net site. It'll save you (and possibly others) a lot of time. Most of the errors can be checked directly in the manual when using certain functions.

0

First, instead of going to different places on the web and gleaning bits of code you'd be better served going to www.w3schools.com, if you haven't already, and going through their PHP tutorial. It's easy, quick and will give you a good basic understanding of PHP. You'll find very few people here who haven't used w3schools at one time or another.

$_SESSION is a variable array that holds your session data, since it's an array use use [ and ] to specify which value you are wanting. In this case it's myusername so you access the session variable by using $_SESSION[myusername]. In PHP functions you use parenthesis so if you wanted to unset that variable you'd use the function unset($_SESSION[myusername]);

So a function uses ( and ) but a variable array uses [ and ].

Also in line 2, which you probably caught already, you have an extra parenthesis right after the equals. Parentheses always come in pairs so if you count the number of parenthesis it should always be an even number. The number one problem I have when coding is lop-sided parentheses and lop-sided braces.

David

thanks David, very helpfull, found the bits i was looking for at via www.w3schools.com .

0

As diet says: $_SESSION(myusername) should be $_SESSION['myusername'] When you were using session_is_registered[myusername] should have been session_is_registered("myusername") As for getting bits from all over and not knowing what you're doing. PLEASE, get a downloadable copy of the php manual from the php.net site. It'll save you (and possibly others) a lot of time. Most of the errors can be checked directly in the manual when using certain functions.

as much as i enjoy trying to read i find it very hard to understand what i have read, i find it easier to play about learning by trial n error bitzing together diffrent code into easy to solve problems that ($X) , this is producing a libary of code that i hope will help others with learning annykey :icon_idea:

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.