-Karl- Posted April 17, 2010 Share Posted April 17, 2010 So in my checklogin.php I have: if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername1"); session_register("mypassword1"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } and in login_success.php: <? session_start(); if(!session_is_registered(myusername1)){ header( 'Location: ./login.php' ) ; } ?> This will then redirect them to the control panel, however, how could I call which username they used, in order to display the correct information as it's different per account. I just can't get my head around it. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/ Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2010 Share Posted April 17, 2010 Just FYI: session_register() is deprecated as of PHP 5.3.0 Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043747 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 Oo, what would you suggest I use? Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043749 Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2010 Share Posted April 17, 2010 You use session_start() and set and reference $_SESSION['....'] variables. session_register, session_is_registered, and session_unregister() were depreciated in php4.2 when register_globals were turned off by default, finally throw a depreciated error in php5.3, and have been completely removed in php6. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043756 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 print_r($_SESSION['myusername1']; will return the correct username, but I've tried creating a variable to use this in a MySQL query, but it just won't work >.> Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043758 Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2010 Share Posted April 17, 2010 Define: "but it just won't work" That could mean a dozen different things and be caused by almost an infinite number of different coding. Due to its' general purpose nature, there is not a "one symptom" only has "one cause" relation ship. No one can tell you what is causing your code to "but it just won't work" without seeing your code and knowing exactly what symptom you saw in front of you that makes you think that it is not working. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043760 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 Okay so I've tried $username = print_r($_SESSION['myusername1']; Then tried using that in a MySQL query, printing the Session normally returns the username. But when placed in a Query, $sql = "SELECT * FROM database WHERE `username` = '$username'"; The page returns blank. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043765 Share on other sites More sharing options...
SaMike Posted April 17, 2010 Share Posted April 17, 2010 Okay so I've tried $username = print_r($_SESSION['myusername1']; Then tried using that in a MySQL query, printing the Session normally returns the username. But when placed in a Query, $sql = "SELECT * FROM database WHERE `username` = '$username'"; The page returns blank. Try this: $username = $_SESSION['myusername1']; $sql = "SELECT * FROM database WHERE `username` = '{$username}'"; Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043772 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 So here's part of my code: // first grab the username $username = $_SESSION['myusername1']; // second query for that username $query = "SELECT * FROM `users` WHERE `username` = '{$username}'"; $run = mysql_query($query); if($run){ // third display the information $arr = mysql_fetch_assoc($run);{ ?> <div style="margin-left:20px; margin-top:20px; margin-bottom:20px;"> <fieldset> <legend>Clan Specific Information</legend> <label for="clanname">User Name:</label><input name="clanname" value="{$arr['username']}" type="text" id="clan" onkeyup="checkUsernameForLength(this);" /> <span class="hint">User names cannot be longer than 50 characters, this can be edited in the administrator section.</span> </fieldset> The thing is, the page loads, but there's nothing displayed, just a blank version of my template basically. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043775 Share on other sites More sharing options...
SaMike Posted April 17, 2010 Share Posted April 17, 2010 Try this: $query = "SELECT * FROM `users` WHERE `username` = '{$username}'"; echo $query; Then copy the query you got, go to phpmyadmin and run it to test if it returns any rows. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043778 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 Try this: $query = "SELECT * FROM `users` WHERE `username` = '{$username}'"; echo $query; Then copy the query you got, go to phpmyadmin and run it to test if it returns any rows. The query echos correctly and it runs in PhpMyAdmin. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043784 Share on other sites More sharing options...
SaMike Posted April 17, 2010 Share Posted April 17, 2010 do you have error reporting on? it would explain blank page if there's error in your coding. You can test it by making new file debug.php : <?php ini_set("display_errors", 1); error_reporting (E_ALL ^ E_NOTICE); include('index.php'); ?> Just replace index.php with the file your working with. Does it still print out blank page? Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043785 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 do you have error reporting on? it would explain blank page if there's error in your coding. You can test it by making new file debug.php : <?php ini_set("display_errors", 1); error_reporting (E_ALL ^ E_NOTICE); include('index.php'); ?> Just replace index.php with the file your working with. Does it still print out blank page? It still prints out the template, with no information in it. Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043793 Share on other sites More sharing options...
-Karl- Posted April 17, 2010 Author Share Posted April 17, 2010 Also, what can I do about the deprecated function session_register? Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043800 Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2010 Share Posted April 17, 2010 I know that isn't the whole script, but I don't see where you call mysql_connect(), or mysql_select_db(). Are you sure the query is executing? $run = mysql_query($query) or die( mysql_error() ); Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043804 Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2010 Share Posted April 17, 2010 You replace session_register() by assigning session variables thusly: $_SESSION['variable'] = "value"; Link to comment https://forums.phpfreaks.com/topic/198849-sessions/#findComment-1043805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.