Jump to content

Sessions


-Karl-

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.