[PHP/HTML] how i can make this work?

Skilled Illusionist
Joined
Jan 14, 2005
Messages
395
Reaction score
2
Fixed

source :
index.html
Code:
<form method="post" action="index.php">
<p>
<input type="text" name="werkt" value="msn" />
<input type="submit" value="Submit" />
</p>
</form>

index.php
PHP:
<?php
if (empty($_REQUEST["werkt"]))
{
print("You did left the field empty go back");
exit(); 
}
elseif ($_REQUEST["werkt"] == 'msn')
{
readfile("data1.txt");
} 
if ($_REQUEST["werkt"] == 'google')
{
readfile("data2.txt");
} 
else 
{
print("That is not supported");
exit(); 
}
?>
thank you for time watching at it :flag_schw
 
Lol.

I use POST instead of REQUEST...

And you can do an elseif for 'google'.

And I generally use echo instead of print, but print is just as good (or better?) I guess, so no problem at all :)

And, if your form gets longer, it might be easier to first check if the submit button is pressed and than do the input checks:

if ($_POST['submit'])
{
[here your error handling of the input]
}

[here displaying the actual form, with the errors if they exist]

Good luck ;)
 
i fixed that now i only got 1 problem left
if someone type google it works but Google dont works
how i can let that happen

source :
PHP:
<?php
if ($_POST['werkt'] == 'hotmail register'){
readfile("data1.txt");
} 
elseif ($_POST['werkt'] == 'google'  'Google'){
readfile("data2.txt");
}
elseif (empty($_POST['werkt'])){
echo ("You did left the field empty go back");
} 
else{
echo ("That is not supported :  ");
echo $_POST['werkt'];
}
?>
 
Code:
elseif (eregi('^google$', $_POST['werkt']))
 
POST is better than REQUEST, but both would work (just pointing out that the request part was not an error) not sure about your function named empty(), I've never seen or used that one.

If your 'werkt' variable isnt set you will have an error, i'd wrap the whole thing in a statement checking for the exsistance of werkt:
isset($_POST['werkt'])


If you are checking for the word google or Google or even GoOgLe why are you using a regular expression? Thats gotta be the hardest way to do it. (well aside from typing all possiblities... PhP has tons of string comparison functions already, and even ones that are case insensitive. Sure sure the regx would work but why?

Maybe you should check out php.net for string functions. A 2 second search brings me this:

int strcasecmp ( string $str1, string $str2 )
Binary safe case-insensitive string comparison.

Well that's exactly what you are looking for.

Go here for more information: PHP: strcasecmp - Manual
and if you want more examples of usage its very similar to strcmp.


Anyway I'd fix your code up and repost, but better if you do that instead of copypasta mine.
 
Oh yeah, sure, strcmp functions are better in this case. I generally use regex for input verification as it can be very complex to verify it without regex, but in this case its better to use php build-in functions :).
 
so
PHP:
   <?php
if (isset($_POST['werkt'] == 'hotmail register')){
readfile("data1.txt");
} 
elseif (isset($_POST['werkt'] == 'google')){
readfile("data2.txt");
}
elseif (empty(isset($_POST['werkt']))){
echo ("You did left the field empty go back");
} 
else{
echo ("That is not supported :  ");
echo isset($_POST['werkt']);
}
?>

thats right that way ?
 
empty(isset($_POST['werkt']))

If $_POST['werkt'] is set, than it will return 1 and won't be empty, else it will return 0 and wont be empty neither, so this will always be true. I guess you only want to check if its empty or not. So get rid of isset();

Get rid of isset(); anyways in the whole code, you probably dont see the purpose of this function. PHP: isset - Manual go there, its the php reference bible.
 
empty(isset($_POST['werkt']))

If $_POST['werkt'] is set, than it will return 1 and won't be empty, else it will return 0 and wont be empty neither, so this will always be true. I guess you only want to check if its empty or not. So get rid of isset();

Get rid of isset(); anyways in the whole code, you probably dont see the purpose of this function. PHP: isset - Manual go there, its the php reference bible.

for the way he did it yeah, but if you are working with a dynamic form (i always build them like they will be dynamic) and the form field of werkt is not on the form your method of just checking $_POST['werkt'] will throw an error. For example if you have a radio button and none get checked, it doesn't pass on the post.

phpinfo(32); //just like that

is your friend in seeing what is being passed. I was only making a point that his empty function seemed silly (to me) and if you want to see if you got the variable (before checking its value) you should use isset, or at least i would.

something like:
PHP:
if (isset($_POST['werkt'])){
//check the values
if ($_POST['werkt'] == 'google'){ 
readfile("data2.txt"); 
} 
}
is what i had in mind, but that's cause the forms I work on change so often (clients changing their minds/totally dynamic content.. and so on)

I hope I explained that well...
 
now i did add something else if you did type in google , hotmail register
than it save's youre ip in ip.txt
how i can export it in ip.php
so is shows :
ip : xxx.xxx.xxx.xxx
from : website.php/html

my index.php
PHP:
<?php

if ($_POST['werkt'] == 'hotmail register'){
$ip = $_SERVER['REMOTE_ADDR'];
$ip2 = $_SERVER['PHP_SELF'];
echo "<br>";
readfile("data1.txt");
echo "</br>";
} 
elseif (eregi('^google$', $_POST['werkt'])){
$ip = $_SERVER['REMOTE_ADDR'];
$ip2 = $_SERVER['PHP_SELF'];
echo "<br>";
readfile("data2.txt");
echo "</br>";

}
elseif (empty($_POST['werkt'])){
$ip = $_SERVER['REMOTE_ADDR'];
$ip2 = $_SERVER['PHP_SELF'];
echo "<br>";
echo ("You did left the field empty go back");
echo "</br>";
} 
else{
echo ("That is not supported :  ");
$ip = $_SERVER['REMOTE_ADDR'];
$ip2 = $_SERVER['PHP_SELF'];
echo "<br>";
echo $_POST['werkt'];
echo "</br>";
}

$filename = 'ip.txt';
$somecontent = "$ip, $ip2, \n";
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'a')) {
         print "Cant find the filename";
         exit;
    }
    if (!fwrite($handle, $somecontent)) {
        print "Cant write to the file";
        exit;
    }
    print "<br><br><br> Succes, ip saved! </br></br></br>";
    fclose($handle);
} else {
    print "the file is unwriteable";
}
?>

my ip.php
PHP:
<?php
include("ip.txt");
include("index.php");
echo "ip : $ip";
echo "from : $ip2";
?>
 
Have you done any research on this one? Remember that you can just google things...

You probably look for something like this:
PHP: explode - Manual
 
(i did repost this replay)
i remaked that script now it just output normal but how i can set every diffrent ip in new window
my script
PHP:
<?php
$myFile = "ip.dat";
$fh = fopen($myFile, 'r');
$theData1 = fread($fh, 25);
$theData2 = fread($fh, 50);
fclose($fh);
?>


<table width="200" border="1">
  <tr>
    <td>ip</td>
    <td><?php echo $theData1; ?></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>ip</td>
    <td><?php echo $theData2; ?></td>
  </tr>
</table>
 
Last edited:
Back