Alright, I am working through yet another example (if anyone has noticed, i do that a lot, lol) from a book and trying to get it to fit what I want to do. The thing is that I haven’t changed the code from what the book has (except where it needs to match my specific settings and file names) and it doesn’t want to work. I went to the book publishers website and downloaded the files and they work fine when I run them.
I have a auth.inc.php file with this php code in it, all in <body>:
[code=php]
<?php
session_start();
if (isset($_SESSION[‘logged’]) && $_SESSION[‘logged’] == 1) {
header(“Refresh: 5; URL=upload.php?redirect=$redirect”);
print “You are being sent to the file upload page.<br/>”;
print “If your browser does not redirect you in 5 seconds <a href=”upload.php?redirect=$redirect”>click here</a> to continue.”;
}
else {
$redirect = $_SERVER[‘PHP_SELF’];
header(“Refresh: 5; URL=login.php?redirect=$redirect”);
print “You will be redirected to the login page.<br/>”;
print “If your browser does not redirect you in 5 seconds <a href=”login.php?redirect=$redirect”>click here</a> to continue.”;
die();
}
?>
And a login.php page with this code, also all in <body>:
[code=php]
<?php
session_start();
$_SESSION[‘logged’] = 0;
if (isset($_POST[‘username’] == “username” && $_POST[‘password’] == “password”) {
$_SESSION[‘logged’] = 1;
header(“Refresh: 5; URL=” . $_POST[‘redirect’] . “”);
print “You are being sent to the file upload page.<br/>”;
print “If your browser does not send you in 5 seconds please <a href-“” . $_POST[‘redirect’]. “”>Click Here</a> to continue.”;
}
else {
?>
[code=html]
<form enctype=”text/plain” action=”<?php echo $_SERVER[“PHP_SELF”]; ?>” method=”post” class=”login”>
<fieldset>
<legend>
Login
</legend>
<label for=”username”>
Username:<br />
<input type=”text” name=”username” id=”username” size=”20″ maxlength=”20″ />
<br />
<br />
</label>
<label for=”password”>
Password:<br />
<input type=”password” name=”password” id=”password” size=”20″ maxlength=”20″ />
<br />
<br />
</label>
<input type=”submit” name=”login” id=”loginbtn” value=”Login” />
</fieldset>
</form>
And a upload.php file with this code in it:
before the <html>:
[code=php]
<?php
include “auth.inc.php”;
?>
down in the <body>:
[code=html]
<form action=”<?php echo $_SERVER[“PHP_SELF”]; ?>” enctype=”multipart/form-data” method=”post”>
<fieldset>
<legend>
Upload File
</legend>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”51200″ />
<label for=”fileupload”>
<br />Your file:<br />
<input type=”file” name=”fileupload” />
</label><br /><br />
<input type=”submit” value=”Upload” />
</fieldset>
</form>
[code=php]
<?php
$file_dir = “..\file\upload\directory”;
foreach($-FILES as $file_name => $file_array) {
echo “path: “.$file_array[‘”tmp_name”‘].”<br/>n”;
echo “path: “.$file_array[‘”name”‘].”<br/>n”;
echo “path: “.$file_array[‘”type”‘].”<br/>n”;
echo “path: “.$file_array[‘”size”‘].”<br/>n”;
If(is_uploaded_file($file_array[‘”temp_name”‘])){
move_uploaded_file($file_array[‘”tmp_name”‘], “$file_dir/”.$file_array[“name”]) or die(“Couldn’t copy”);
print “File was uploaded successfully!<br/>”;
}
}
?>
Now, what is supposed to happen is when the user clicks the link to upload a file it points to the upload.php page, and it checks to make sure that they are logged in by checking their session. If they are not logged in it is supposed to redirect them to the login.php page and if they are logged in it should let them see the upload.php page and upload a file. What does happen is when I try to open upload.php I just get a blank page. Also, if I just open up the auth.inc.php page it says I am already logged in and brings me to the upload page, which also shows up as a blank page. Do I have the php code in the wrong place on the page, or is there something I am just not seeing? Thanks.