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
https://forums.phpfreaks.com/topic/225301-cant-find-the-page/
Share on other sites

Well, if the page in the header is in the same folder as the page you're are being redirected from than it should work, however if it's not, than you should either use full path (http://...) or use other marks to mark the target file (for example ../page.php or folder/files/index.php).

Link to comment
https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163557
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
https://forums.phpfreaks.com/topic/225301-cant-find-the-page/#findComment-1163590
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.