Return username from MySQL

Status
Not open for further replies.

Cat

New Member
Sep 2, 2013
12
0
Hei. Sorry for bad english.
I use (from here) and I don't know how to return something like "Welcome {username}". I've tried with print_r ($_SESSION); but returns Array ( [loggedin] => 1 ).
Please help me! Also, if it's possible to have a page like user.php?user={username} when show informations about {username}. Thanks!
 
Last edited:

Cat

New Member
Sep 2, 2013
12
0
$_SESSION['username']
Notice: Undefined index: username in www\1\index.php on line 5
Line 5: echo 'Hi', $_SESSION['username'];.

From what I see, $ _SESSION can only return 0 (if not connected) or 1 (if connected).
 
Last edited:

Heaplink

Developer & Designer
Nov 9, 2011
510
173
After reading through the login.php file for the script you mentioned, it does not register a variable called username in the global $_SESSION variable. To fix this, add this to your login.php
PHP:
$_SESSION['username'] = $username;
right below the $_SESSION['loggedin'] = "1";
 
  • Like
Reactions: Cat

Cat

New Member
Sep 2, 2013
12
0
After reading through the login.php file for the script you mentioned, it does not register a variable called username in the global $_SESSION variable. To fix this, add this to your login.php
PHP:
$_SESSION['username'] = $username;
right below the $_SESSION['loggedin'] = "1";
Thanks for reply. I added $_SESSION['username'] = $username; after $_SESSION['loggedin'] = "1"; and before header("Location: index.php"); but still don't work; same error.
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
I did it now and and it worked. Many thanks!
How I can make your post "best answer"?
No problem :)

Unfortunately this thread is made in a request section, so you can't mark my answer as the best answer. The thread would have to be moved to a Help section.
 
  • Like
Reactions: Cat

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
You need to be checking if they logged in first before echoing that. Look at main.php
The shorthand echo method in PHP isn't advised, some web servers don't allow it.

But it seems this problem is sorted. Closed. (also moved to help & support)
 
Last edited:
Status
Not open for further replies.

Users who are viewing this thread

Top