Jump to content

Recommended Posts

I've almost got my login script working, but for some reason the username string is not passing to my successful.php page.

 

Code

 

--------------------------------------------

 

<?php
session_start();

include 'config.php';

// Connect to server and select databse.
//mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
//mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$username=$_POST['username']; 
$password=$_POST['password']; 

// captures username & passwords, so they can be passed on to other pages
session_register("username");

$sql="SELECT * FROM nixon WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matches table row must be 1 row
if($count==1){

header("location: successful.php");
}
else {
header ("Location: again.html");
}
?>

 

------------------------

 

Any assistance would be of great help!  Thanks!

 

(edited by kenrbnsn to add


tags)

Link to comment
https://forums.phpfreaks.com/topic/130660-session-string-not-passing-to-next-page/
Share on other sites

Certainly... the login form  and the receiving successful page are below...

 

---------------------

Login Form

 

<div id="dispanel">
  <table width="750" border="0" background="../images/graybk.jpg">
    <tr>


      <td width="736" colspan="3"><form name="form2" method="post" action="member.php">	  

        <table width="736" height="221" border="0">
          <tr>
            <td height="21"> </td>
            <td colspan="3" align="left" valign="top"> </td>
            <td> </td>
          </tr>
          <tr>
            <td width="13" height="22"> </td>
            <td colspan="3" align="left" valign="top"><p class="style13 style23">Registered User Login</p>
              </td>
            <td width="12"> </td>
          </tr>
          <tr>
            <td> </td>
            <td width="163"> </td>
            <td width="167"> </td>
            <td width="359"> </td>
            <td> </td>
          </tr>
          <tr>
            <td> </td>


            <td><span class="style3 style30">Username</span></td>
            <td><label>
              <input name="username" type="text" id="username">


            </label></td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td> </td>


            <td><span class="style3 style30">Password</span></td>
            <td><input name="password" type="text" id="password"></td>


            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td> </td>
            <td> </td>
            <td><label>
       			  <input name="submit" type="submit" id="submit" value="Login" />
		  
            </label></td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td height="21"> </td>
            <td colspan="3"> </td>
            <td> </td>
          </tr>
          <tr>
            <td height="21"> </td>
            <td colspan="3"><hr /></td>
            <td> </td>
          </tr>
        </table>

------------

 

Successful page that should receive the session strings...

 

<?php 
session_start();

include 'config.php';

echo "Welcome,".$username;

?>

 

--------------------------

 

Thanks in advance!

 

(edited by kenrbnsn to add


tags)

 

I just purchased a tutorial that gave an example of the session string, and the tutorial is not formatted as $_SESSION['thing'] = 'formstring';

 

It's formatted

$loggedin="username";

session_register("loggedin");

 

Please see attachment for actual screen capture of example code...

 

Is this not correct?

 

[attachment deleted by admin]

i believe it is correct, but it's rather old, and i don't really know how to do things the old way  ;). if you're in a hurry to get this solved, you really should check out the examples on the page i gave you. otherwise, i hope someone who knows what they're talking about will come along.  :P

 

sorry to be so unhelpful...

Read the notes in the manual...

http://uk.php.net/session_register

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

Thanks...

 

I got it to work whe I use

 

$_SESSION['loggedin'] = $username;

session_register("loggedin");

 

but I was wondering why I couldn't get it to work using the format in the tutorial, which is...

 

// captures username to be passed on to other pages

$loggedin = $username;

session_register("loggedin");

 

thanks!

 

[attachment deleted by admin]

Its because your tutorial is outdated.  In modern php versions, registered globals is set to off (as it should be because its a big security risk).  As Ken said and I tried to point out, do not use session_register().

 

page 1:

<?php
session_start();
$_SESSION['loggedin'] = $username;
?>

 

page 2 and so on...

<?php
session_start();
$username=$_SESSION['loggedin'];
echo $username;
?>

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.