Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sessions
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JHanson90




PostPosted: Wed May 19, 2004 4:57 pm   Post subject: Sessions

I'm using the following tutorial for sessions:
http://www.phpfreaks.com/tutorials/41/0.php
I tried it out. But I got this error at the very top of my site on my localhost testserver:
___________________________________________________
Warning: session_start(): open(/tmp\sess_247bb29b5e0a20f637ecd709348c7e4e, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php on line 6

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php on line 6

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php:6) in C:\Program Files\Apache Group\Apache2\htdocs\jwd\romanempiretest\index.php on line 7
I followed all the instructions in the tutorial. Is it the the tutorial that's wrong, or something that I'm doing? If it's something that I'm doing, I'll have to copy and paste some of my coding....
Sponsor
Sponsor
Sponsor
sponsor
JHanson90




PostPosted: Sun May 23, 2004 4:34 pm   Post subject: (No subject)

OK the user does login, and then the next page it says if your session username and password are correct, then display the members area, else then say WRONG please try again. In the members area, there is a link to file upload. You go to that link, and it says if the session username and password that the user inout two pages ago are TRUE, then allow them to use the file upload, else display Sorry please go back to the login page.
This is giving me problems. Here is the code:
INDEX.PHP ::
code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
$module = $HTTP_GET_VARS['module'];
        if($module == 'login') {
        session_start();
        header("Cache-control: private");
        } elseif ($module == 'membersarea') {
        session_start();
        header("Cache-control: private");
        } elseif ($module == 'fileupload') {
        session_start();
        header("Cache-control: private");
        } else { }
$username = $_POST['memberu'];
$password = $_POST['memberpass'];
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
md5($password)
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php echo "<meta http-equiv=\"pics-label\" content='(pics-1.1 \"http://www.icra.org/ratingsv02.html\" comment \"ICRAonline EN v2.0\" l gen true for \"http://www.romanempire.co.nr/\" r (nz 1 vz 1 lz 1 oz 1 cb 1) \"http://www.rsac.org/ratingsv01.html\" l gen true for \"http://www.romanempire.co.nr/\" r (n 0 s 0 v 0 l 0))'>\n"; ?>
<link href="style.css" rel="stylesheet" type="text/css">
<?php
                if($module == 'news') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - News</title>';
                } elseif ($module == 'announcements') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Announcements</title>';
                } elseif ($module == 'memberslist') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Members List</title>';
                } elseif ($module == 'ranks') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Ranks</title>';
                } elseif ($module == 'recruitment') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Recruitment</title>';
                } elseif ($module == 'rules') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Rules</title>';
                } elseif ($module == 'diplomacy') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Diplomacy</title>';
                } elseif ($module == 'serverinfo') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Server Information</title>';
                } elseif ($module == 'downloads') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Downloads</title>';
                } elseif ($module == 'screenshots') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Screenshots</title>';
                } elseif ($module == 'contact') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Contact</title>';
                } elseif ($module == 'affiliation') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Affiliation</title>';
                } elseif ($module == 'memberphp') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Member PHP</title>';
                } elseif ($module == 'login') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Login</title>';
                } elseif ($module == 'membersarea') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Members Area</title>';
                } elseif ($module == 'fileupload') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - File Upload</title>';
                } elseif ($module == 'testmember_form') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Test Member Form</title>';
                } elseif ($module == 'uploadpass') {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius - Upload Password</title>';
                } else {
                        echo '<title>Roman Empire Clan Website - Created by Tiberius</title>';
                                };
?>
</head>

<body>
<?php include("values1.php"); ?>
<table width="750" border="0" align="center" cellspacing="1">
  <tr>
    <td bgcolor="#333333"><?php
include("bannerset.php");
      print ("<br>");
include("affiliatesset.html"); ?><br>
          <table width="683" border="0" align="center" cellspacing="1">
            <tr>
              <td valign="top"><?php
                                if($module == 'news') {
                        include("newsset.php");
                } elseif ($module == 'announcements') {
                        include("announcementsset.html");
                } elseif ($module == 'memberslist') {
                        include("membersset.php");
                } elseif ($module == 'ranks') {
                        include("ranksset.html");
                } elseif ($module == 'recruitment') {
                        include("recruitset.html");
                } elseif ($module == 'rules') {
                        include("rulesset.html");
                } elseif ($module == 'diplomacy') {
                        include("diplomacyset.html");
                } elseif ($module == 'serverinfo') {
                        include("serverinfoset.html");
                } elseif ($module == 'downloads') {
                        include("downloadsset.html");
                } elseif ($module == 'screenshots') {
                        include("screenshotset.html");
                } elseif ($module == 'contact') {
                        include("contactset.html");
                } elseif ($module == 'affiliation') {
                        include("affiliationset.html");
                } elseif ($module == 'memberphp') {
                        include("memberphpset.php");
                } elseif ($module == 'login') {
                        include("loginset.php");
                } elseif ($module == 'membersarea') {
                        include("membersareaset.php");
                } elseif ($module == 'fileupload') {
                        include("uploadset.php");
                } elseif ($module == 'testmember_form') {
                        include("tm_fset.php");
                } elseif ($module == 'uploadpass') {
                        include("uploadpassset.php");
                } else {
                        include("newsset.php");
                                };
                                                                                ?>
                          </td>
              <td valign="top"><?php include("naviset.php"); ?></td>
            </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td bgcolor="#333333"><div align="center">
    <?php include("bottomset.html"); ?></div></td>
  </tr>
</table>
</body>
</html>


Login Pageset (included on the index page IF the URL says ?module=login) ::
code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<title>LoginSet</title>
</head>

<body>
<table width="516" border="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td width="510" valign="top" bgcolor="#79715C"><img src="images/Banner1.jpg" width="510" height="100"></td>
  </tr>
  <tr>
    <td bgcolor="#79715C"><div align="center" class="articletitle">:: Roman Empire Members Only Area Login ::</div></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#79715C"><table width="510"  border="0" align="center" cellpadding="8" cellspacing="1">
        <tr>
          <td align="center" bgcolor="#000000"><strong>Members Area Login</strong><br><br>
            <form action="index.php?module=membersarea" method="POST">
              <table width="191"  border="0" cellspacing="1" bgcolor="#79715C">
                          <tbody>
                <tr align="center" bgcolor="#79715C">
                  <td align="right" bgcolor="#79715C">Username:</td>
                  <td align="center" bgcolor="#79715C"><input name="memberu" type="text" class="form2"></td>
                </tr>
                <tr align="center" bgcolor="#79715C">
                  <td align="right" bgcolor="#79715C">Password:</td>
                  <td align="center" bgcolor="#79715C"><input name="memberpass" type="password" class="form2"></td>
                </tr>
                <tr align="center" bgcolor="#79715C">
                  <td colspan="2"><input type="submit" class="formbutton" value="Enter }R{ Members Area"></td>
                </tr>
                                </tbody>
              </table>
            </form></td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html>


Members Area Pageset (included in the index.php IF the URL says ?module=membersarea) ::
code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link href="style.css" rel="stylesheet" type="text/css">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>MembersAreaSet</title>
</head>

<body>
<table width="516" border="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td width="510" valign="top" bgcolor="#79715C"><img src="images/Banner1.jpg" width="510" height="100"></td>
  </tr>
  <tr>
    <td bgcolor="#79715C"><div align="center" class="articletitle">:: Roman Empire Members Only Area ::</div></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#79715C">
        <?php
        if($_SESSION['username'] == 'testuser' && $_SESSION['password'] == 'testpass') { ?><table width="510" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000">
      <tr>
        <td align="center" bgcolor="#000000">Welcome to the Members Area, <?php echo $_SESSION['username']; ?>.<br>
          <br>
          <table width="150" border="0" align="right" cellspacing="1" bgcolor="#000000">
            <tr>
              <td align="center" bgcolor="#000033">&raquo; Members Navigation &laquo;</td>
            </tr>
            <tr>
              <td align="center" bgcolor="#000000"><a href="index.php?module=fileupload">Upload Files</a></td>
            </tr>
          </table>          </td>
      </tr>
    </table>
        <?php } else { ?>
      <table width="510" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000">
        <tr>
          <td align="center" bgcolor="#000000"><strong>WRONG!</strong><br>
          <br>
          Please try again, or stop trying to get into the Members Only Area.<br>
          <br>
          <a href="index.php?module=login">&laquo; Back to Login Page </a></td>
        </tr>
      </table>
          <?php } ?></td>
  </tr>
</table>
</body>
</html>


File Upload Pageset (included in the index.php IF the URL says ?module=fileupload) ::
code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<title>UploadSet</title>
</head>

<body>
<table width="516" border="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td width="510" valign="top" bgcolor="#79715C"><img src="images/Banner1.jpg" width="510" height="100"></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#79715C"><div class="articletitle">:: Roman Empire File Uploading Service ::</div></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#79715C">      <?php
          if($_SESSION['username'] == 'testuser' && $_SESSION['password'] == 'testpass') { ?>
      <table width="510" border="0" cellpadding="5" cellspacing="1" bgcolor="#000000">
        <tr>
          <td align="center" bgcolor="#000000"><strong>File Upload</strong><br>
            <br>
            <table width="90%" border="0" cellspacing="1">
              <tr>
                <td><span class="style2">Please review these rules before you upload your file.</span><br>
&bull; Maximum File Size is 1 MB.<br>
&bull; No media files.<br>
&bull; No uploads that are just being used as image hosts for other websites.<br>
&bull; Relevant files.<br>
&bull; All files other than .gif, .jpg, .jpeg, or .png must be put inside a .zip file.<br>
&bull; Please <a href="index.php?module=contact">contact</a> the webmaster for requests or suggestions for this area.</td>
              </tr>
            </table>
            <br>
                    <form enctype="multipart/form-data" action="index.php?module=fileupload" method="post">
              <input type="hidden" name="MAX_FILE_SIZE" value="1048576">
                          <input name="userfile" type="file" class="uploadform">
              <br>
                      <input name="upload" type="submit" class="formbutton" id="upload" value="Upload">
                </form>   
          <?php
                  // if you need to put this back into action... // <?=$_SERVER['PHP_SELF'] and the the ? with the > :)
$upload_dir = 'userfiles/';

//SEPERATE THE EXTENTIONS WITH A "",. I.E: "GIF", "JPG", "BMP"....and so on
$allowed_extentions = array("gif", "jpg", "png", "jpeg", "zip");


//Check to make sure a file was selected.

        //If selected - continue

if(!isset($_FILES['userfile'])) {
    echo 'Please select the file you would like to upload. ';
} else {

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {



            //change image name to all lower case



                $imgname = strtolower($_FILES['userfile']['name']);

/* This is the checking part, weather the extension of the file is
   what is allwoed to be uploaded */

   $full_path = $upload_dir . $imgname;
   
   $extension = array_pop(explode(".", $full_path));

   if (in_array($extension, $allowed_extentions)) {



            //remove all spaces from image name



                $imgname = str_replace(" ","",$imgname);



            //check to see if file already exists

            //If not - copy file and continue. Otherwise error out



            if (!file_exists($upload_dir . $imgname) && is_dir($upload_dir)) {

               

                copy($_FILES['userfile']['tmp_name'],$upload_dir . $imgname);
                echo 'Successfully uploaded your file.<br>
                                The location (URL) of the file should be,
                                with all lowercase letters,
                                and all spaces taken out,<br>
                                <a href="http://www.jhanson90.vzz.net/romanempire/userfiles/';echo $imgname;echo '">http://www.jhanson90.vzz.net/romanempire/userfiles/'.$imgname;echo '</a>';
               


            } else {

              echo 'Unable to upload your file, sorry.';

              exit;



            }
           
           
           
   } else {
                echo 'Sorry, you attempted to upload a file that is not allowed to be uploaded on this server.<br>';
                echo 'You may only upload files with these extensions:<br>';
                 
                $number_total = count($allowed_extentions);

                    for($i = 0; $i < $number_total; $i++)
                        {   

                        echo $allowed_extentions[$i] . '<br>';
                        }
                echo 'Please try again.';
   }
}
}



?></td>
        </tr>
      </table>     
      <?php } else { ?>
      <table width="510" border="0" cellpadding="5" cellspacing="1" bgcolor="#000000">
      <tr>
            <td align="center" bgcolor="#000000"><strong>Sorry.</strong><br>
              <br>
              You are not allowed to access this file.<br>
              <br>
            <a href="index.php?module=login">&laquo; Please Login </a> </td>
        </tr>
    </table>
    <?php } ?></td>
  </tr>
</table>
</body>
</html>


And the result on localhost and on my Host Ultra webserver is ERRORS GALORE Crying or Very sad
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: