/    Sign up×
Community /Pin to ProfileBookmark

Identical pages: 1 works, 1 doesn’t…

All right. Now I’m mad.

I just posted this and got logged out and it didn’t appear, so let’s try it again.

Bottom Line:

I have 2 nearly identical pages, 1 works, and 1 does not.

Section 1 “login.php”:

[code=php]
<?php

ob_start();

require (‘templates/template1.html’);

session_start();

?>

<script language=”Javascript” type=”text/javascript”>
<!–

function validForm(passForm) {
if (passForm.username.value == “”) {
alert(“Please enter your username.”)
passForm.username.focus()
return false
}
if (passForm.pass.value == “”) {
alert(“Please enter your password.”)
passForm.pass.focus()
return false
}
if (passForm.pass.value != passForm.confirm.value) {
alert(“Entered passwords did not match.”)
passForm.pass.focus()
passForm.pass.select()
return false
}
return true

}

// –>
</script>

<h1 align=”center”>Log In</h1>

<?php

if (isset ($_SESSION[‘username’])) {
print (“<p>Error! You are already logged in!</p>”);
} else {

?>

<p>Please note that “Character Name” refers to your Animal Crossing character’s name.</p>

<form action=”loggedin.php” method=”post” onsubmit=”return validForm(this)”>

<p>Username: <input type=”text” name=”username” /></p>
<p>Character Name: <input type=”text” name=”character” /></p>
<p>Password: <input type=”password” name=”pass” /></p>
<p>Confirm Password: <input type=”password” name=”confirm” /></p>
<p><input type=”submit” value=”Log In” /></p>

</form>

<?php

}

require (‘templates/template2.html’);

ob_end_flush();

?>
[/code]

Section 1 “loggedin.php”:

[code=php]
<?php

ob_start();

require (‘templates/template1.html’);

session_start();

$username = $_POST[‘username’];
$password = $_POST[‘pass’];
$confirm = $_POST[‘confirm’];
$character = $_POST[‘character’];

if ($password != $confirm) {
print (“<p>Passwords did not match. Please go back and try again. P.S. You don’t have javascript enabled.</p>”);
} else {
switch ($username) {
case “Stevos”:
switch ($password) {
case “sarahatamian”:
$_SESSION[‘username’] = $username;
$_SESSION[‘password’] = $password;
$_SESSION[‘character’] = $character;
print (“<p>Thank you. You are now logged in as ” . $_SESSION[‘username’] . “.</p>”);
header (‘Location: index.php’);
exit();
break;
default:
print (“<p>That password does not match the username you entered.</p>”);
break;
}
break;
case “Rhalyth”:
switch ($password) {
case “leeroy666”:
$_SESSION[‘username’] = $username;
$_SESSION[‘password’] = $password;
$_SESSION[‘character’] = $character;
print (“<p>Thank you. You are now logged in as ” . $_SESSION[‘username’] . “.</p>”);
header (‘Location: index.php’);
exit();
break;
default:
print (“<p>That password does not match the username you entered.</p>”);
break;
}
break;
case “Gayle”:
switch ($password) {
case “sarahatamian”:
$_SESSION[‘username’] = $username;
$_SESSION[‘password’] = $password;
$_SESSION[‘character’] = $character;
print (“<p>Thank you. You are now logged in as ” . $_SESSION[‘username’] . “.</p>”);
header (‘Location: index.php’);
exit();
break;
default:
print (“<p>That password does not match the username you entered.</p>”);
break;
}
default:
print (“<p>We have no record of that username. If you are not an admin, you will not be able to sign in here.</p>”);
break;
}
}

require (‘templates/template2.html’);

ob_end_flush();

?>
[/code]

Section 2 “login.php”:

[code=php]
<?php

ob_start();

require (‘templates/template1.html’);

session_start();

?>

<script language=”Javascript” type=”text/javascript”>
<!–

function validForm(passForm) {
if (passForm.username.value == “”) {
alert(“Please enter your username.”)
passForm.username.focus()
return false
}
if (passForm.pass.value == “”) {
alert(“Please enter your password.”)
passForm.pass.focus()
return false
}
if (passForm.pass.value != passForm.confirm.value) {
alert(“Entered passwords did not match.”)
passForm.pass.focus()
passForm.pass.select()
return false
}
return true

}

// –>
</script>

<h1 align=”center”>Log In</h1>

<?php

if (isset ($_SESSION[‘uhusername’])) {
print (“<p>Error! You are already logged in!</p>”);
} else {

?>

<p>Please note that “Character Name” refers to your Animal Crossing character’s name.</p>

<form action=”http://stevos404.t35.com/uh/loggedin.php” method=”post” onsubmit=”return validForm(this)”>

<p>Username: <input type=”text” name=”username” /></p>
<p>Character Name: <input type=”text” name=”character” /></p>
<p>Password: <input type=”password” name=”pass” /></p>
<p>Confirm Password: <input type=”password” name=”confirm” /></p>
<p><input type=”submit” value=”Log In” /></p>

</form>

<?php

}

require (‘templates/template2.html’);

ob_end_flush();

?>
[/code]

Section 2 “loggedin.php”:

[code=php]
<?php

ob_start();

require (‘templates/template1.html’);

session_start();

$username = $_POST[‘username’];
$password = $_POST[‘pass’];
$confirm = $_POST[‘confirm’];
$character = $_POST[‘character’];

if ($password != $confirm) {
print (“<p>Passwords did not match. Please go back and try again. P.S. You don’t have javascript enabled.</p>”);
} else {
switch ($username) {
case “Stevos”:
switch ($password) {
case “sarahatamian”:
$_SESSION[‘uhusername’] = $username;
$_SESSION[‘uhpassword’] = $password;
$_SESSION[‘uhcharacter’] = $character;
print (“<p>Thank you. You are now logged in as ” . $_SESSION[‘username’] . “.</p>”);
header (‘Location: index.php’);
exit();
break;
default:
print (“<p>That password does not match the username you entered.</p>”);
break;
}
break;
case “Rhalyth”:
switch ($password) {
case “leeroy666”:
$_SESSION[‘uhusername’] = $username;
$_SESSION[‘uhpassword’] = $password;
$_SESSION[‘uhcharacter’] = $character;
print (“<p>Thank you. You are now logged in as ” . $_SESSION[‘username’] . “.</p>”);
header (‘Location: index.php’);
exit();
break;
default:
print (“<p>That password does not match the username you entered.</p>”);
break;
}
break;
case “Gayle”:
switch ($password) {
case “sarahatamian”:
$_SESSION[‘uhusername’] = $username;
$_SESSION[‘uhpassword’] = $password;
$_SESSION[‘uhcharacter’] = $character;
print (“<p>Thank you. You are now logged in as ” . $_SESSION[‘username’] . “.</p>”);
header (‘Location: index.php’);
exit();
break;
default:
print (“<p>That password does not match the username you entered.</p>”);
break;
}
default:
print (“<p>We have no record of that username. If you are not an admin, you will not be able to sign in here.</p>”);
break;
}
}

require (‘templates/template2.html’);

ob_end_flush();

?>
[/code]

Section 1 works, Section 2 does not.

If you need more information, please ask. I put a lot in the first try, but now I’m just annoyed.

Sorry if it’s just a stupid and obvious syntax error.

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 25.2006 — Can you define "works" versus "does not" work? Do you get any error messages? (Is error-reporting enabled and have you set error_reporting(E_ALL); to make sure you're seeing all errors and warnings?)

Personally, I'm too lazy to look through a couple hundred lines of code when I have no idea what I'm looking for.
Copy linkTweet thisAlerts:
@shane_carrAug 25.2006 — if (isset ($_SESSION['uhusername'])) {

in login.php should be

if (isset ($_SESSION['username'])) {

unless that's the variable name you set; also, I noticed

print ("<p>Thank you. You are now logged in as " . $_SESSION['username'] . ".</p>");

header ('Location: index.php');

which won't header anything since something was sent to the browser
Copy linkTweet thisAlerts:
@NintendoGamerSTauthorAug 26.2006 — [B]NogDog [/B] - Sorry about that. Frustration made me forget. But when I try to run Section 2, instead of the form being processed by "loggedin.php", it just goes blank and refreshes the page, whereas in Section 1, everything works perfectly fine and the page returns to "index.php".

[B]shane.carr[/B] - Sections 1 & 2 log into different areas of the site, so you need to log into each section seperately. Because of this, I want to create 2 differently named sessions, "username" for Section 1, and "uhusername" for section 2. Secondly, it WILL header something because of output buffering:

[code=php]
ob_start();

//Here's some code

ob_end_flush();
[/code]


Once output buffering starts, it will keep anything from being put on the page until the "ob_end_flush();" function ends it. This allows headers, sessions, cookies, etc. to be used virtually anywhere in the script without getting the ever so common "Headers already sent by..." error message.

Thanks
Copy linkTweet thisAlerts:
@shane_carrAug 26.2006 — Hmm... I guess I didn't see the ob_start();
Copy linkTweet thisAlerts:
@shane_carrAug 26.2006 — I've looked through your code, and I actually went to your site and tried out the form (the url is listed in the code), and it submitted the form to login.php, so I'm thinking that validForm() is returning false. Take it out and see what happens.
Copy linkTweet thisAlerts:
@NintendoGamerSTauthorAug 26.2006 — Thanks shane.carr, but which one did you try? Section 1 "login.php" or Section 2 "login.php"?

Either way, I really appreaciate your help.

P.S. Section 1 is the one with the blue background and Section 2 is the one with the black.
Copy linkTweet thisAlerts:
@NintendoGamerSTauthorAug 26.2006 — Alright. I removed the javascript in Section 2 (the NOT working one), but still have no results. I'm starting to think it's my host, but I could be wrong. Thanks again for reading through the 288 lines of coding i produced! I really appreciate it!
Copy linkTweet thisAlerts:
@shane_carrAug 26.2006 — It [i]shouldn't[/i] be a host problem; I tried login.php #2 and it sure did submit to login.php and not loggedin.php like it's supposed to. My last try is make the form action relative, because it is in the one with the blue background which works; see what happens

<form action="loggedin.php" method="post">
Copy linkTweet thisAlerts:
@NintendoGamerSTauthorAug 26.2006 — All right. I'll try that and see how it goes. Thanks again.
Copy linkTweet thisAlerts:
@NintendoGamerSTauthorAug 26.2006 — Nope. Not helping. Thanks though.
Copy linkTweet thisAlerts:
@shane_carrAug 26.2006 — Are there any rewrite rules in .htaccess?
×

Success!

Help @NintendoGamerST spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...