Jump to content

Can't find the page


xuniter

Recommended Posts

i have the following code which should redirect the user to the index.php page, but instead it shows error 404 page not found....Please if anyone see the problem help me

 

login.php

<?php session_start(); ?>
<html>
<head>
<title>Basic CMS | Admin area Login</title>
</head>
<body>
<?php
if (isset($_SESSION['user'])) {
header("Location: index.php");
} else {
?>
<form action="dologin.php method="post">
<table>
<tr>
    	<td><span>Username:</span></td>
        <td><input type="text" name="username" /></td>
</tr>
<tr>
    	<td><span>Password:</span></td>
        <td><input type="password" name="password" /></td>
</tr>
<tr>
        <td colspan="2" align="right"><input type="submit" name="login" value="Login"/></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>

 

 

dologin.php

<?php session_start(); ?>
<html>
<head>
<title>Basic CMS | Admin area Login</title>
</head>
<body>
<?php
if (isset($_SESSION['user'])) {
header("Location: index.php");
} else {
?>
<form action="dologin.php method="post">
<table>
<tr>
    	<td><span>Username:</span></td>
        <td><input type="text" name="username" /></td>
</tr>
<tr>
    	<td><span>Password:</span></td>
        <td><input type="password" name="password" /></td>
</tr>
<tr>
        <td colspan="2" align="right"><input type="submit" name="login" value="Login"/></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>

 

index.php

<?php
session_start();
if(isset($_SESSION['user'])) {
?>
<html>
<head>
<title>Basic CMS | Admin area</title>
</head>
<body>

</body>
</html>
<?php
} else {
header("Location: login.php");
}
?>

Link to comment
Share on other sites

Hi xuniter,

The problem is with the form action. You're missing an end quote:

<form action="dologin.php method="post">

should be

<form action="dologin.php" method="post">

 

Also, headers need to be sent before anything is output to the page. It is best to move your php code containing the header command to the top of the page before <html>, etc. There's no need to use an else command. If the condition is not met then the code will just continue. If it is met then the header will redirect to the new page.

Cheers,

Fergal

 

<?php 

if (isset($_SESSION['user'])) {
header("Location: index.php");
} 
?>
<html>
<head>


<title>Basic CMS | Admin area Login</title>

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.