Jump to content

[SOLVED] If ane Else statements


supermerc

Recommended Posts

Hey, Im trying to make it so that when someone goes to my website on the right there will be a login form if they arnt logged in, and if they are, I include a little welcome page.

 

<?php
     if($_SESSION['s_logged_n'] = 'true'){
 include'welcome.php';
 }
 else{
 echo'<form method="post" action="login.php">
  <p align="center"><span class="style15">Username:<br>
      <input name="username" type="text" class="textBox" id="username" size="20">
      <br>
    Password:<br>
    <input name="password" type="password" class="textBox" id="password" size="20">
    <br>
    Click <a href="register.php" target="main">Here</a> To Register
    </span><br>
    <input name="login" type="submit" class="textBox" id="login" value="Submit">
            </form>';
		}
      ?> 

 

But right now, as soon as you go on my page, http://random.awardspace.biz/ It includes welcome.php even when you arnt logged in.

 

If you want to test it out use test as username and testtest as password.

Link to comment
Share on other sites

setting a cookie when they login and deleting it when they log out then:

 


if (isset($_COOKIE['test'])) {

   // Welcome.php

}
else {

  // login script

}

 

Don't use sessions because they get deleted once they close the web browser, unless you want them to login each time the visit. But cookies are the best way to go either way.

Link to comment
Share on other sites

try mine agin and use <?php session_start(); ?> on every page that has sessions on it.

 

I already have session start, here is my full code:

 

<?php
session_start();
require("config.php");
require("functions.php");
?>
<html>
<head>
<style type="text/css"> body{ margin: 0; } </style>
<title>My Site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<!-- DO NOT DELETE THE MARGIN TAGS, THESE STOP WHITE GAPS ON ALL EDGES OF THE PAGE -->

<?php
include 'header.php';
?>

   <!-- START OF MAIN CONTENT AREA -->
   <tr><table width="100%" border="0">
  <tr>
    <td valign="top" width="220"><!-- START OF NAVIGATION --><table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4%"><img src="images/lborder.gif" width="21" height="24"></td>
                <td width="90%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Main 
                    Navigation</font></div></td>
                <td width="6%"><img src="images/rborder.gif" width="6" height="24"></td>
              </tr>
              <tr>
                <td colspan="3"><table width="195" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse">
                    <tr>
                      <td> 
                        <!-- START OF CONTENT BOX CONTENT -->
                        <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><?php include'navigation.php'; ?> </font> 
                        <!-- END OF CONTENT BOX CONTENT -->                      </td>
                    </tr>
                  </table></td>
              </tr>
            </table><!-- END OF NAVIGATION --><br><!-- START OF NAVIGATION --><table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4%"><img src="images/lborder.gif" width="21" height="24"></td>
                <td width="90%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Main 
                    Navigation</font></div></td>
                <td width="6%"><img src="images/rborder.gif" width="6" height="24"></td>
              </tr>
              <tr>
                <td colspan="3"><table width="195" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse">
                    <tr>
                      <td> 
                        <!-- START OF CONTENT BOX CONTENT -->
                        <font size="1" face="Verdana, Arial, Helvetica, sans-serif">text etc here</font> 
                        <!-- END OF CONTENT BOX CONTENT -->                      </td>
                    </tr>
                  </table></td>
              </tr>
            </table><!-- END OF NAVIGATION --></td>
    <td width="100%" valign="top"><!--MAIN CENTER CONTENT AREA START-->
            <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td><img src="images/lborder.gif" width="21" height="24"></td>
                <td width="100%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">News</font></div></td>
                <td><img src="images/rborder.gif" width="6" height="24"></td>
              </tr>
              <tr> 
                <td colspan="3"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse">
                    <tr> 
                      <td> <div align="center"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">News will go here. </font> 
                        </div></td>
                    </tr>
                  </table></td>
              </tr>
            </table><br><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td><img src="images/lborder.gif" width="21" height="24"></td>
                <td width="100%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Main 
                    Content Area</font></div></td>
                <td><img src="images/rborder.gif" width="6" height="24"></td>
              </tr>
              <tr> 
                <td colspan="3"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse">
                    <tr> 
                      <td> <div align="center"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Your Content! </font> 
                        </div></td>
                    </tr>
                    <tr>
                      <td bgcolor="#E8E8E8"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Copyright 
                          2005 - Random - All Rights Reserved </font></div></td>
                    </tr>
                  </table></td>
              </tr>
            </table>
            <!--MAIN CENTER CONTENT AREA END--></td>
    <td width="220" valign="top"><!-- START OF NAVIGATION -->
        <table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="4%"><img src="images/lborder.gif" width="21" height="24"></td>
            <td width="90%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Members Area</font></div></td>
            <td width="6%"><img src="images/rborder.gif" width="6" height="24"></td>
          </tr>
          <tr>
            <td colspan="3"><table width="195" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse">
                <tr>
                  <td><!-- START OF CONTENT BOX CONTENT -->
                      <font size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <?php
     if($_SESSION['s_logged_n'] == 'true'){
 include'welcome.php';
 }
 else{
 echo'<form method="post" action="login.php">
  <p align="center"><span class="style15">Username:<br>
      <input name="username" type="text" class="textBox" id="username" size="20">
      <br>
    Password:<br>
    <input name="password" type="password" class="textBox" id="password" size="20">
    <br>
    Click <a href="register.php" target="main">Here</a> To Register
    </span><br>
    <input name="login" type="submit" class="textBox" id="login" value="Submit">
            </form>';
		}
      ?> 
                      </font>
                      <!-- END OF CONTENT BOX CONTENT -->                  </td>
                </tr>
            </table></td>
          </tr>
        </table>
      <!-- END OF NAVIGATION --></td>
  </tr>
</table>

    <td colspan="2"> </td>
  </tr>
  <!-- END OF MAIN CONTENT AREA -->
</table>
</html>

Link to comment
Share on other sites

<?php

if($_SESSION['s_logged_n']){
 include'welcome.php';
 }
 else{
 echo'<form method="post" action="login.php">
  <p align="center"><span class="style15">Username:<br>
      <input name="username" type="text" class="textBox" id="username" size="20">
      <br>
    Password:<br>
    <input name="password" type="password" class="textBox" id="password" size="20">
    <br>
    Click <a href="register.php" target="main">Here</a> To Register
    </span><br>
    <input name="login" type="submit" class="textBox" id="login" value="Submit">
            </form>';
		}
      ?> 
           

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.