0

Hi all,

I am creating a online c.v
but do not want it open to every one so i have made a simple login file
but want the page to re-direct when the login is correct,

<?php
$user = "user";
$pass = "pass"

if ($_POST["username"] != $user && $_POST["pass"] != $pass ) { ?>

<form method="post" action="index.php" >
Username: <input type="text" name="username" />
<br/>
Password: <input type="text" name="pass" />
<br/>
<input type="submit" value="login" />

<?php } else { ?>

Now how would i re-direct the person i know how to re-direct them when the page loads but not this way.
Im confused with thisand would like to get my c.v up online asap so any help would be very appriciated
Thank you

5
Contributors
8
Replies
10
Views
7 Years
Discussion Span
Last Post by mktgmgr101
0

Hi all,

I am creating a online c.v
but do not want it open to every one so i have made a simple login file
but want the page to re-direct when the login is correct,

<?php
$user = "user";
$pass = "pass";

if ($_POST["username"] != $user && $_POST["pass"] != $pass ) { ?>

<form method="post" action="index.php" >
Username: <input type="text" name="username" />
<br/>
Password: <input type="text" name="pass" />
<br/>
<input type="submit" value="login" />

<?php } else { ?>

Now how would i re-direct the person i know how to re-direct them when the page loads but not this way.
Im confused with thisand would like to get my c.v up online asap so any help would be very appriciated
Thank you

<?php
//connect ur dabase.
$user = "username";
$pass = "pass"

if ($_POST["username"] != $user && $_POST["pass"] != $pass ) { ?>

<form method="post" action="index.php" >
Username: <input type="text" name="username" />
<br/>
Password: <input type="text" name="pass" />
<br/>
<input type="submit" value="login" />

<?php } else { 
$select=mysql_query("select * from tablename where username=$user and password=$pass");
$count=mysql_num_rows($select);
if($count==1)
{
//redirect page

header('Location: http://www.example.com/');

exit;
}else
{
echo "login failed";
}
}
?>

Edited by muralikalpana: n/a

0
<?php
//connect ur dabase.
$user = "username";
$pass = "pass"

if ($_POST["username"] != $user && $_POST["pass"] != $pass ) { ?>

<form method="post" action="index.php" >
Username: <input type="text" name="username" />
<br/>
Password: <input type="text" name="pass" />
<br/>
<input type="submit" value="login" />

<?php } else { 
$select=mysql_query("select * from tablename where username=$user and password=$pass");
$count=mysql_num_rows($select);
if($count==1)
{
//redirect page

header('Location: http://www.example.com/');

exit;
}else
{
echo "login failed";
}
}
?>

Just keep in mind there is a T_if error there and a column ( ; ) will need adding on line 4.

0

forgot to mention there is no mysql database in use, every one use's the same login info

0
<?php
//since no database is being used, below is the username/password for everybody
$username = "username";
$password = "password";

if (($_POST['username'] == $username) && ($_POST['password'] == $password) ) { ?>

header('Location: nextPage.php');
exit;

} else { ?>

<form method="post" action="index.php" >
Username: <input type="text" name="username" />
<br/>
Password: <input type="text" name="password" />
<br/>
<input type="submit" value="login" />

<?php

}

?>
0

header(); works fine, though not always.. i found this little treasure on the web.. it's better to use..

$url = "whereto.php"; // target of the redirect
$delay = "0"; // seconds of delay
echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
die();

just put this in place of


header('Location: nextPage.php');
exit;

Edited by mktgmgr101: added some text..

0

header(); works fine, though not always.. i found this little treasure on the web.. it's better to use..

$url = "whereto.php"; // target of the redirect
$delay = "0"; // seconds of delay
echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
die();

just put this in place of


header('Location: nextPage.php');
exit;

Also if you want to delay the header you can use the following.

$delay=2; //seconds
sleep($delay);
header('Location: nextPage.php');
//no html output before the header function
exit;

And in addition the header function is always much faster providing you use the exit; line. This is because the user doesn't need to downloading any content to be redirected where as the html method an entire page would need to be transfered. Also note that the meta redirect is not compatible with all browsers unlike the header function.

0

@cwarn23 is also correct.. i guess you can just try which solution best suits your work.. here is a link to some additional info regarding headers() http://www.jonasjohn.de/snippets/php/headers.htm

@cwarn23 - good work.. thanks for the added info..

Also if you want to delay the header you can use the following.

$delay=2; //seconds
sleep($delay);
header('Location: nextPage.php');
//no html output before the header function
exit;

And in addition the header function is always much faster providing you use the exit; line. This is because the user doesn't need to downloading any content to be redirected where as the html method an entire page would need to be transfered. Also note that the meta redirect is not compatible with all browsers unlike the header function.

Edited by mktgmgr101: added something..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.