Asked By
Barrett
0 points
N/A
Posted on - 08/29/2011
Hi,
I have a problem with PHP Script. Please help me if anybody knows? The requirement is when we get the student login form, it shows the username in the username text box if it available in the cookie else it just leaves a blank space for user typing". But when I run the script, It shows the following script "<?=$_COOKIE['username'] ?>" in the user text box which I used in the php file. How is it comes? I also sent attachment files php script, sql database. And also sent the error image here.
Display php script in the text box at student log in form
Hi.Â
I didn't find your PHP script attachment. But, maybe there is a problem in your coding. Check all the opening symbols and closing symbols. The problem is mainly focus on that side of the area. Make sure that all the opening tags are closed with the closing tags. You may have done some type of problem with the symbols. Check your PHP script with the following I am providing here below:
if((isset($_COOKIE['username'])) && (isset($_COOKIE['password'])))
{
$username = $_COOKIE['username'];
$password = $_COOKIE['password'];
Regards,
Phani.
Answered By
mughal
5 points
N/A
#118701
Display php script in the text box at student log in form
I have the code below checking to see if cookies are set & if they are set then display the page & if they aren't set then to display the login box. When I login with correct username & password I set 2 cookies which hold encrypted un & pw. For some reason it is like the cookies that ARE set are only being read if I go directly to the page by typing in the page in the URL & won't be read if I go to the page by link from another page.
Step I
After I login I am taken to the index.php by header("Location: index.php");…If I type in the URL domain.com/page2.php & click the " Go " button or hit the enter key it will display my page for me.
Step II
After I login I am taken to the index.php by header("Location: index.php");…Instead of typing in the URL page2.php, I click on a link in the index.php page to take me to page2.php it will not display the page. I can then immediately click the " Go " button for the URL to take me to the page2.php it will display the page for me.
My login.php page:<?php
require("left.php");
require("cdb.php");
if(isset($_GET['do']))
{
$show = $_GET['do'];
If ($show == 'Login')
{
echo'<div id="content">';
echo'<div class="feature" align="center">';
echo'<br>';
include("login_box.php");
echo'</div>';
echo'</div>';
}
elseif ($show == 'login')
{
if((isset($_COOKIE['username'])) && (isset($_COOKIE['password'])))
{
echo'<div id="content">';
echo'<div class="feature" align="center">';
echo'<div class="error">You are already logged in!';
echo'<br>';
echo'</div>';
echo'</div>';
}
else
{
$username = $_POST['username'];
$password = md5(md5($_POST['password']));
$loguser = mysql_query("SELECT * FROM $customer_table WHERE customers_username = '$username' AND customers_password = '$password'");
$rows = @mysql_num_rows($loguser);
if($rows == 0)
{
echo'<div id="content">';
echo'<div class="feature" align="center">';
echo'<div class="error">Incorrect Login Credentials!';
echo'<br>';
echo'<br>';
echo'Please try again</div>';
echo'<br>';
include("login_box.php");
echo'</div>';
echo'</div>';
}
else
{
setcookie("username", $username, time()+3600); //Lasts for 1 Hr
setcookie("password", $password, time()+3600); //Lasts for 1 Hr
echo 'Successfully Logged in!';
header("Location: index.php");
}
}
}
elseif ($show == 'logout')
{
if((isset($_COOKIE['username'])) && (isset($_COOKIE['password'])))
{
$username = $_COOKIE['username'];
$password = $_COOKIE['password'];
setcookie("username", $username, time()-3600);
setcookie("password", $password, time()-3600);
echo 'Loged Out Successfully!';
require("login_box.php");
}
else
{
echo'<div id="content">';
echo'<div class="feature" align="center">';
echo'<div class="error">You are not logged in!';
echo'<br>';
echo'<br>';
echo'Please try again below:</div>';
echo'<br>';
include("login_box.php");
echo'</div>';
echo'</div>';
}
}
}
else
{
header("Location: index.php");
}
?>
My page2.php <?php
require("left.php");
if((isset($_COOKIE['username'])) && (isset($_COOKIE['password'])))
{
require("main/bankwire.php");
}
else
{
echo'<div id="content">';
echo'<div class="feature" align="center">';
echo'<div class="error">You must be logged in to complete an order';
echo'<br>';
echo'Please login below</div>';
echo'<br>';
include("login_box.php");
echo'</div>';
echo'</div>';
}
?>