Page 1 of 1
Input Function?
Posted: Thu Aug 05, 2010 12:02 pm
by marvolo1300
Is there an input function in php that is as easy to use as "cin" in c++?
What i am trying to do is create a website which is available to all users on my LAN. I want them to enter a code which will redirect them to the folder from which they can download files from. I don't want to create a MySQL database to store the access code because I don't know much about it and I only started learning php yesterday. I understand that the way i am planning on using is vulnerable to user-injected scripts. i just want to deter certain people from accessing certain files.
Here's what i have come up with
Code: Select all
//The file name is login.php
<html>
<body>
<?php
$real_id = "access code" ;
$ui_login_id ;
//i need the user to input the code here and the value of ui_login_id should change to whatever the user inputted
if (ui_login_id == real_id)
{
include ("login_success.php");
}
else include ("login_fail") ;
?>
</body>
</html>
Code: Select all
//the file name is login_success.php
<body>
<html>
<?php
echo "You will now be redirected to my Sharing Folder in 3 seconds";
echo <br>;
echo "If you are not redirected in 3 seconds please ";
echo '<a href="http://192.168.1.105/Sharing Files">, click here</a>';
header('Refresh: 3; URL=http://192.168.1.105/Sharing Files/');
?>
</body>
</html>
Code: Select all
//the filename is login_fail.php
<body>
<html>
<?php
echo "You have entered the wrong login password";
include ("login.php"); // this creates a loop
?>
</body>
</html>
Re: Input Function?
Posted: Thu Aug 05, 2010 12:55 pm
by marvolo1300
I googled "input field php" and i came up with this half-solution. it still doesn't work..
Code: Select all
//the file name is login.php
<html>
<body>
<?php
$real_id = "entry id" ;
$ui_login_id ;
<form method="post" action="method">
<input type="text" name="Access Id" value="ui_login_id">
<input type="submit" value="Submit">
if (ui_login_id == real_id)
{
include ("login_success.php");
}
else include ("login_fail") ;
?>
</body>
</html>
Re: Input Function?
Posted: Thu Aug 05, 2010 1:16 pm
by shawngoldw
your on the right path...
Code: Select all
<form method="post" action="login.php">
<input type="text" name="Access_Id" value="ui_login_id">
<input type="submit" value="Submit">
</form>
Then in login.php
Code: Select all
$ui_login_id = $_POST["Access_Id"];
The action attribute tells the form which file to send the form info to. Method will not do anything. You also need to close the form with a </form> tag. $_POST["Access_Id"] is how you retrieve the inputted data from the form.
For string comparisons you can not say
Instead use:
Code: Select all
strcmp($ui_login_id, $real_id) == 0
strcmp is the string comparison function, it returns 0 when the strings are the same.
Also in your login_success and login_failed files
you have your tags in this order:
it needs to be the other way:
Also in your login_failed you are printing html and body tags but then including the login.php file which will print them again.
Hope this helps!
Re: Input Function?
Posted: Thu Aug 05, 2010 2:01 pm
by marvolo1300
Code: Select all
//the file name is login.php
<html>
<body>
<?php
$real_id = "entry id" ;
$ui_login_id ;
<form method="post" action="method">
<input type="text" name="Access Id" value="ui_login_id">
<input type="submit" value="Submit">
if (ui_login_id == real_id)
{
include ("login_success.php");
}
else include ("login_fail") ;
?>
</body>
</html>
[/quote]
Hi, I have made all the changes you recommended but i still get this error when trying to open login.php through my browser
[text]Parse error: parse error, unexpected '<' in C:\EasyWAMP\www\login.php on line 9[/text]
This is my revised code :
Code: Select all
//the file name is login.php
//i initialized a new integer ($comparison) to receive the value of the string comparison between $real_id and $ui_login_id in line 16
//i corrected the html and body tags
<html>
<body>
<?php
$real_id = "google";
$comparison ;
<form method="post" action="login.php">
<input type="text" name="Access_Id" value="ui_login_id">
<input type="submit" value="Submit">
</form>
$ui_login_id = $_POST["Access_Id"];
strcmp($ui_login_id, $real_id) == $comparison;
if (comparison == 0)
{
include ("login_success.php");
}
else include ("login_fail") ;
?>
</body>
</html>
Code: Select all
// the filename is login_success.php
// i fixed the html and body tags
<html>
<body>
<?php
echo "You will now be redirected to my Sharing Folder in 3 seconds";
echo <br>;
echo "If you are not redirected in 3 seconds please ";
echo '<a href="http://192.168.1.105/Sharing Files">, click here</a>';
header('Refresh: 3; URL=http://192.168.1.105/Sharing Files/');
?>
</body>
</html>
Code: Select all
//the filename is login_fail.php
// i created another .php file to avoid have two sets of html and body tags
// i also fixed the html and body tags
<html>
<body>
<?php
echo "You have entered t;he wrong login password";
include ("login_fail_repeat.php");
?>
</body>
</html>
Code: Select all
/the filename is login_fail_repeat.php
// i created this to avoid two sets of tags
<?php
$real_id = "google";
$comparison ;
<form method="post" action="login.php">
<input type="text" name="Access_Id" value="ui_login_id">
<input type="submit" value="Submit">
</form>
$ui_login_id = $_POST["Access_Id"];
strcmp($ui_login_id, $real_id) == $comparison;
if (comparison == 0)
{
include ("login_success.php");
}
else include ("login_fail") ;
?>
Re: Input Function?
Posted: Thu Aug 05, 2010 2:19 pm
by shawngoldw
You can't put the html markup inside the php code like that
Either echo the html or end the php tag, write the html, and start a new php tag like the following:
Code: Select all
//the file name is login.php
//i initialized a new integer ($comparison) to receive the value of the string comparison between $real_id and $ui_login_id in line 16
//i corrected the html and body tags
<html>
<body>
<?php
$real_id = "google";
$comparison ;
?>
<form method="post" action="login.php">
<input type="text" name="Access_Id" value="ui_login_id">
<input type="submit" value="Submit">
</form>
<?php
$ui_login_id = $_POST["Access_Id"];
strcmp($ui_login_id, $real_id) == $comparison;
if (comparison == 0)
{
include ("login_success.php");
}
else include ("login_fail") ;
?>
</body>
</html>
Re: Input Function?
Posted: Thu Aug 05, 2010 2:19 pm
by AbraCadaver
You need to open and close PHP tags depending on whether it's PHP or HTML:
Code: Select all
<?php
//php code
?>
<some html code>
<?php
//more php code
?>
Re: Input Function?
Posted: Thu Aug 05, 2010 3:09 pm
by marvolo1300
[quote="AbraCadaver"]You need to open and close PHP tags depending on whether it's PHP or HTML:
Like this?
Code: Select all
<?php
$accessid;
$comparison;
?>
Please enter your access ID
<form method="post" action="">
<input type="password" name="accessid" >
<input type="submit" value="Submit">
</form>
<?php
$_GET["accessid"] = $comparison;
if ($comparison == "201nc")
{
include "login_success.php";
}
else include ("login_fail.php");
?>