Jump to content

sessions


franknu

Recommended Posts

ok here is the full code for my page1.

 

this:  <pre>_SESSION:<?php print_r($_SESSION); ?></pre>

 

is displaying this

_SESSION:Array

(

    [user_Name] =>

    [Password] =>

)

 


<?php 
session_start(); 
$_SESSION['User_Name'] =$User_Name;
$_SESSION['Password'] =$Password; 
?>
<html>
<head>
<title>Member Session</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
</head>

<body>

<?
$host     = "";
$username = "";
$password = "";
$database = "";
$db = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());



$BusinessName = (isset($_POST['BusinessName']) ? $_POST['BusinessName'] : '');
$Slogan = (isset($_POST['Slogan']) ? $_POST['Slogan']:'');
$Business_Address = (isset($_POST['Business_Address']) ? $_POST['Business_Address']:'');
$Tel = (isset($_POST['Tel']) ? $_POST['Tel']:'');
$Website = (isset($_POST['Website']) ? $_POST['Website']:'');
$Email = (isset($_POST['Email']) ? $_POST['Email']:'');
$Member_Status = (isset($_POST['Member_Status']) ? $_POST['Member_Status']:'');
$Fax =(isset($_POST['Fax']) ? $_POST['Fax']:'');
$type = (isset($_POST['type']) ? $_POST['type']:'');
$make = (isset($_POST['make']) ? $_POST['make']:'');
$Categories = (isset($_POST['Categories']) ? $_POST['Categories']:'');
$Keyword = (isset($_POST['Keyword']) ? $_POST['Keyword']:'');
$Picture1 =  (isset($_POST['Picture1']) ? $_POST['Picture1']:'');
$Headline =  (isset($_POST['Headline']) ? $_POST['Headline']:'');
$Slogan2 = (isset($_POST['Slogan2']) ? $_POST['Slogan2']:'');
$Description1 = (isset($_POST['Description1']) ? $_POST['Description1']:'');
$Description2 = (isset($_POST['Description2']) ? $_POST['Description2']:'');
$Description3= (isset($_POST['Description3']) ? $_POST['Description3']:'');
$Contact2 = (isset($_POST['Contact2']) ? $_POST['Contact2']:'');
$Picture2 =  (isset($_POST['Picture2']) ? $_POST['Picture2']:'');
$Picture3 = (isset($_POST['Picture3']) ? $_POST['Picture3']:'');
$Picture4 =  (isset($_POST['Picture4']) ? $_POST['Picture4']:'');
$User_Name = (isset($_POST['User_Name']) ? $_POST['User_Name']:'');
$Password = (isset($_POST['Password']) ? $_POST['Password']: '');
$User_Name=strtolower($_POST['User_Name']);
$Password=strtolower($_POST['Password']);

if ( isset($_POST['User_Name']) && isset($_POST['Password']) ) {


$query = "SELECT * FROM business_info WHERE User_Name='$User_Name' AND Password ='$Password' ";


}

  if ($result = mysql_query($query)) 
{
    if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);

      $BusinessName= $row['BusinessName'];
      $Keyword = $row['Keyword'];
      $Picture1 =  $row['Picture1'];
      $Headline = $row['Headline'];
      $Slogan =$row['Slogan'];
      $Slogan2 = $row['Slogan2'];
      $Description1 =$row['Description1'];
      $Description2 = $row['Description2'];
      $Description3= $row['Description3'];
      $Contact2 =  $row['Contact2'];
      $Picture2 = $row['Picture2'];
      $Picture3 = $row['Picture3'];
      $Categories=$row['Categories'];
      $Business_Address= $row['Business_Address'];
      $make=$row['make'];
      $type=$row['type'];
      $Tel= $row['Tel'];
      $Website=$row['Website'];
    } 
else 
{
      echo "<p><b>username and/or password not found. Try
again?

</b></p>";
exit;
    }
  } 
else 
{
    echo "Query failed<br />$query<br />". mysql_error();
exit;
  }



?>



<table width="504" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td width="494">

<table width="497" border="0">
      <tr>
        <td width="487">banner
<pre>_SESSION:<?php print_r($_SESSION); ?></pre> 

</td>
      </tr>
      <tr>
  

      
   
<td background="fondo2.jpg">
<? echo " Welcome  <b>$BusinessName </b>"; ?> 
</td>

     </tr>
      <tr>
        <td><table width="480" border="0">
          <tr>
            <td width="52" valign="top"><table width="204" border="0">
              <tr>
                <td width="194"><table width="210" border="1">
                  <tr>
                    <td width="200" background="fondo2.jpg"> <div align="center"><strong>My Front Picture </strong></div></td>
                  </tr>
                  <tr>
                    <td height="130" valign="top">
<?

$image = preg_replace('#^.*/public_html#', '', $row['Picture1']);
            echo '<img src="' . $image . '" width="150" height="141">'; 
?>


                    </td>
                  </tr>
                  <tr>
                    <td><table width="200" border="1">
                      <tr>
                        <td width="80"> </td>
                        <td width="104">Update</td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td><table width="200" height="129" border="1">
                  <tr>
                    <td height="23" background="fondo2.jpg"><div align="center">My Tools </div></td>
                  </tr>
                  <tr>
                    <td valign="top"><table width="200" border="1">
                      <tr>
                        <td width="21"> </td>
                        <td width="153">Messages</td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td>Sell Online </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td>Send Email </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td>Message Board </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td>Post a Job </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td>Add Emails</td>
                      </tr>
                    </table></td>
                  </tr>
                </table>                  
                        </td>
              </tr>
              <tr>
                <td height="152" valign="top"><table width="200" border="1">
                  <tr>
                    <td height="23" background="fondo2.jpg"><p align="center"><strong>Forum</strong></p>                      </td>
                  </tr>
                  <tr>
                    <td><table width="200" border="1">
                      <tr>
                        <td width="30"> </td>
                        <td width="144"> </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td> </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td> </td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td> </td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
            <td width="412">
		<br>			<table width="451" border="0">
              <tr>
                <td width="445"><table width="440" border="1">
                  <tr>
                    <td width="430" background="fondo2.jpg"><div align="center" class="style1">Update My Towns Webpage</div></td>
                  </tr>
                  <tr>
                    <td><table width="430" border="1">
                      <tr>
                        <td width="108"><a href="text_update.php">Update Page</a></td>
                        <td width="138">Update colors</td>
                        <td width="162">UpdateBackground</td>
                      </tr>
                      <tr>
                        <td>Update U-Tube</td>
                        <td>Update Videos</td>
                        <td>Update Sound</td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="241"><table width="439" border="1">
                  <tr>
                    <td width="429" bordercolor="#E0DFE3" background="fondo2.jpg"><div align="center" class="style1"> Update Picture </div></td>
                  </tr>
                  <tr>
                    <td height="188"><table width="430" border="1">
                      <tr>
                        <td width="154"> <?

$image = preg_replace('#^.*/public_html#', '', $row['Picture2']);
            echo "<img src='$image' width='75' height='75'>";
?>
</td>
                        <td width="260">Update</td>
                      </tr>
                      <tr>
                        <td>

<?

$image = preg_replace('#^.*/public_html#', '', $row['Picture3']);
            echo "<img src='$image' width='75' height='75'>";
?>

</td>
                        <td>Update</td>
                      </tr>
                      <tr>
                        <td><?

$image = preg_replace('#^.*/public_html#', '', $row['Picture4']);
            echo "<img src='$image' width='75' height='75'>";
?>
</td>
                        <td>Update</td>
                      </tr>
                      <tr>
                        <td><?

$image = preg_replace('#^.*/public_html#', '', $row['Picture5']);
            echo "<img src='$image' width='75' height='75'>";
?>
</td>
                        <td>Update</td>
                      </tr>
                      <tr>
                        <td><?

$image = preg_replace('#^.*/public_html#', '', $row['Picture6']);
            echo "<img src='$image' width='75' height='75'>";
?>
</td>
                        <td>Update</td>
                      </tr>
                      <tr>
                        <td> </td>
                        <td>Update</td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="241" valign="top"><table width="439" border="1">
                  <tr>
                    <td background="fondo2.jpg"><div align="center"><strong>User Identification </strong></div></td>
                  </tr>
                  <tr>
                    <td><table width="433" border="1">
                      <tr>
                        <td width="108">User Name </td>
                        <td width="92"> <input type="text" name="User_Name" value="$User_Name"></td>
                        <td width="100">Password</td>
                        <td width="101"><input type="text" name="Password" value="$Password"></td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
            </table>              <p> </p>
              <p> </p>
              <p> </p>
              <p> </p></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td> </td>
      </tr>
    </table></td>
  </tr>
</table>';
?>
</body>
</html>

 

please help

 

Link to comment
Share on other sites

Ok i did some changes and i got  a little improvement base on what u said. Yes the way u have it set up that is the logic i have.

 

 

but here is the change i made

<?
if ( isset($_POST['User_Name']) && isset ( $_POST['Password']) ) { 
        session_start(); 
        session_regenerate_id(); 
        $_SESSION = array('User_Name'=>$_POST['User_Name']); 
     
}
?>

 

also it is still not carrin the User_Name onto the next page

but is defenely and improvement

this line is displaying this..<pre>_SESSION:<?php print_r($_SESSION); ?></pre>

 

_SESSION:Array

(

    [user_Name] => franklin

)

 

the problem is that i should also display the password and it is only displaying the user

 

 

Link to comment
Share on other sites

Ok,

 

You want to move

$_SESSION['User_Name'] =$User_Name;
$_SESSION['Password'] =$Password; 

 

below the part where your setting the $User_Name & $Password variables.

 

session_start() needs to be the first item in the code, but the 2 sessions vars can be set later after you have verified that the username and password are indeed correct.

 

That is why they are not populating correctly. Keep session_start() where it is at, and move those 2 session vars below the

 

if ($result = mysql_query($query)) 
{

Link to comment
Share on other sites

Ok On Page1

 

with <pre>_SESSION:<?php print_r($_SESSION); ?></pre>

 

i am displaying this

 

SESSION:Array

(

    [user_Name] => franklin

    [Password] => franklin01

)

 

 

and here is my code

<?
if ( isset($_POST['User_Name']) && isset ( $_POST['Password']) ) { 
        session_start(); 
        session_regenerate_id(); 
  $_SESSION = array('User_Name'=>$_POST['User_Name'] , 
                                 'Password'=>$_POST['Password']); 
           
}
?>

 

however on page2

 

 

i am displaying

 

SESSION:Array

(

    [user_Name] =>

    [Password] =>

)

 

with  <pre>_SESSION:<?php print_r($_SESSION); ?></pre>

 

and this is the code for page2


<?php 
session_start(); 
if (isset($_SESSION['User_Name']) && isset($_SESSION['Password']))  { 
session_regenerate_id(); 
        $_SESSION = array('User_Name'=>$_POST['User_Name'] , 
                                 'Password'=>$_POST['Password']);        
} 
?>



<html>

Link to comment
Share on other sites

Humor me on this and try this. Create 2 new pages. Call them page1.php & page2.php.

 

page1.php

<?php
session_start();

$_SESSION['test1']='This is test1 session variable';
$_SESSION['test2']='This is test2 session variable';
?>
<a href="page2.php">Go To Page 2</a>

 

page2.php

 

<?php

session_start();

echo $_SESSION['test1'];
echo '<br>';
echo $_SESSION['test2'];

?>

 

Open page1.php, and click the link to page2. You should see the 2 session variables there.

 

The reason for this is to ensure that sessions are properly working on your system

 

 

however....

 

<?php 
session_start(); 
if (isset($_SESSION['User_Name']) && isset($_SESSION['Password']))  { //if sessions are set here
session_regenerate_id(); 
        $_SESSION = array('User_Name'=>$_POST['User_Name'] , // your resetting them here to the post data.. it don't look like the post data is being sent to this page, so you would be setting them to blank
                                 'Password'=>$_POST['Password']);        
} 
?>

It looks like your form is submitting to itself. If it is not submitting to page 2 then the post variables are going to be lost when you redirect or move to page 2

 

Try that and lemme know how it goes.

 

Link to comment
Share on other sites

Ok another observation,

 

I use the same codes that u provide me on the same pages that i am workin on and they work fine;

 

by now i am assuming that it is the way i am using User_Name And Password that i am having problems with

 

please help

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.