validation - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

validation

UndilUndil Posts: 7Member
I'm working on a forum script for my website. i have a problem with the validation script. It goes like this:



<?php

#forum id is valid
$valid = false;
$filename = "valid.dat";
$fs = fopen($filename,"r");
while(!feof($fs)) {
if($forum == fgets($fs)) { $valid = true; }
if(!$valid) ++$ForumNumber;
}
if($forum == "") { $valid = false; }

fclose($fs);

#load variables
if($valid == true)
{
$filename = $ForumNumber.".dat";
echo $filename;
}

?>



The valid.dat file contains one line (for now), which is "yohomyth".
I enter "valid.php?forum=yohomyth" as the URL, and i've done a few tests that lead me to believe that for some reason the $forum is NEVER valid. Can anybody help? Thanx in advance.

Comments

  • codecraigcodecraig Posts: 163Member
    : I'm working on a forum script for my website. i have a problem with the validation script. It goes like this:
    :
    :
    :
    : <?php
    :
    : #forum id is valid
    : $valid = false;
    : $filename = "valid.dat";
    : $fs = fopen($filename,"r");
    : while(!feof($fs)) {
    : if($forum == fgets($fs)) { $valid = true; }
    : if(!$valid) ++$ForumNumber;
    : }
    : if($forum == "") { $valid = false; }
    :
    : fclose($fs);
    :
    : #load variables
    : if($valid == true)
    : {
    : $filename = $ForumNumber.".dat";
    : echo $filename;
    : }
    :
    : ?>
    :
    :
    :
    : The valid.dat file contains one line (for now), which is "yohomyth".
    : I enter "valid.php?forum=yohomyth" as the URL, and i've done a few tests that lead me to believe that for some reason the $forum is NEVER valid. Can anybody help? Thanx in advance.
    :
    :


    Try printing out the fgets(...)... to see what it contains. Perhaps it contains blank space, etc...so when you compare "yohomyth" to "yohomyth " they are not equal. Let me know if you find anything.

    So do
    [code]
    print "FGETS: " . fgets($fs);
    [/code]

    If you are getting white space, I believe there are PHP Functions to strip out stuff like that.

    Peace,



    [size=5][italic][blue]Code[/blue][black]:[/black][red]Craig[/red][/italic][/size]

  • DarQDarQ Posts: 1,625Member
    [b][red]This message was edited by Moderator at 2003-12-22 7:37:33[/red][/b][hr]
    [red]
    http://php.net/manual/function.trim.php

    additional:
    rtrim() and ltrim().
    [/red]

    : If you are getting white space, I believe there are PHP Functions to strip out stuff like that.
    :
    : Peace,
    :
    :
    :
    : [size=5][italic][blue]Code[/blue][black]:[/black][red]Craig[/red][/italic][/size]
    :
    :

    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    url--> http://mark.space.servehttp.com
  • emperoremperor Posts: 59Member
    [b][red]This message was edited by emperor at 2003-12-22 8:27:23[/red][/b][hr]
    fgets() returns each line with the newline included ("
    " for unix systems, "
    " for windows). Like DarQ says, use rtrim() which should strip newlines and carriage returns, and try that.


  • netgertnetgert Posts: 331Member
    Try
    [code]
    $forum = HTTP_GET_VARS["forum"];
    [/code]
    before the code you posted. The GET-POST parameters might not have been associated with the global variables
    : I'm working on a forum script for my website. i have a problem with the validation script. It goes like this:
    :
    :
    :
    : <?php
    :
    : #forum id is valid
    : $valid = false;
    : $filename = "valid.dat";
    : $fs = fopen($filename,"r");
    : while(!feof($fs)) {
    : if($forum == fgets($fs)) { $valid = true; }
    : if(!$valid) ++$ForumNumber;
    : }
    : if($forum == "") { $valid = false; }
    :
    : fclose($fs);
    :
    : #load variables
    : if($valid == true)
    : {
    : $filename = $ForumNumber.".dat";
    : echo $filename;
    : }
    :
    : ?>
    :
    :
    :
    : The valid.dat file contains one line (for now), which is "yohomyth".
    : I enter "valid.php?forum=yohomyth" as the URL, and i've done a few tests that lead me to believe that for some reason the $forum is NEVER valid. Can anybody help? Thanx in advance.
    :
    :

    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • emperoremperor Posts: 59Member
    : Try
    : [code]
    : $forum = HTTP_GET_VARS["forum"];
    : [/code]
    : before the code you posted. The GET-POST parameters might not have been associated with the global variables

    Best use $_GET['forum'] - the HTTP_GET_VARS array is pretty much obsolete (only still supported for backward compatibility)
  • DarQDarQ Posts: 1,625Member
    : : Try
    : : [code]
    : : $forum = HTTP_GET_VARS["forum"];
    : : [/code]
    : : before the code you posted. The GET-POST parameters might not have been associated with the global variables
    :
    : Best use $_GET['forum'] - the HTTP_GET_VARS array is pretty much obsolete (only still supported for backward compatibility)
    :
    [red]
    5 points for emperor. HTTP_GET_VARS __should__ not be used any longer.
    [/red]
    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    url--> http://mark.space.servehttp.com

  • netgertnetgert Posts: 331Member
    I know that. I wrote it so because still a lot of ppl use older version of PHP which doesn't have $_GET $_POST $_REQUEST $_SERVER and $_COOKIE arrays. If he/she would have incuded he version he/she is using, I would have written the up-to-date version

    : : : Try
    : : : [code]
    : : : $forum = HTTP_GET_VARS["forum"];
    : : : [/code]
    : : : before the code you posted. The GET-POST parameters might not have been associated with the global variables
    : :
    : : Best use $_GET['forum'] - the HTTP_GET_VARS array is pretty much obsolete (only still supported for backward compatibility)
    : :
    : [red]
    : 5 points for emperor. HTTP_GET_VARS __should__ not be used any longer.
    : [/red]
    : [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    : url--> http://mark.space.servehttp.com
    :
    :

    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • DarQDarQ Posts: 1,625Member
    you should assume that coders have a decent version. this also encourages users to upgrade if they haven't done this before. only specific (version-deprecated) questions should be answerd in a deprecated way.

    : I know that. I wrote it so because still a lot of ppl use older version of PHP which doesn't have $_GET $_POST $_REQUEST $_SERVER and $_COOKIE arrays. If he/she would have incuded he version he/she is using, I would have written the up-to-date version
    :
    : : : : Try
    : : : : [code]
    : : : : $forum = HTTP_GET_VARS["forum"];
    : : : : [/code]
    : : : : before the code you posted. The GET-POST parameters might not have been associated with the global variables
    : : :
    : : : Best use $_GET['forum'] - the HTTP_GET_VARS array is pretty much obsolete (only still supported for backward compatibility)
    : : :
    : : [red]
    : : 5 points for emperor. HTTP_GET_VARS __should__ not be used any longer.
    : : [/red]
    : : [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    : : url--> http://mark.space.servehttp.com
    : :
    : :
    :
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :

    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    url--> http://mark.space.servehttp.com

  • netgertnetgert Posts: 331Member
    gonna remember that. just wanted to be cross-version compatible and avoid reply like $forum is still null after $_GET["forum"]...
    i always use the new form as i have php 4.3.4. but i have helped many ppl using the new form and got negative replys because they forgot to mention they have ancient php and they can't update it because they're not the administrators. so there should be a posting rule: include your php version

    : you should assume that coders have a decent version. this also encourages users to upgrade if they haven't done this before. only specific (version-deprecated) questions should be answerd in a deprecated way.
    :
    : : I know that. I wrote it so because still a lot of ppl use older version of PHP which doesn't have $_GET $_POST $_REQUEST $_SERVER and $_COOKIE arrays. If he/she would have incuded he version he/she is using, I would have written the up-to-date version
    : :
    : : : : : Try
    : : : : : [code]
    : : : : : $forum = HTTP_GET_VARS["forum"];
    : : : : : [/code]
    : : : : : before the code you posted. The GET-POST parameters might not have been associated with the global variables
    : : : :
    : : : : Best use $_GET['forum'] - the HTTP_GET_VARS array is pretty much obsolete (only still supported for backward compatibility)
    : : : :
    : : : [red]
    : : : 5 points for emperor. HTTP_GET_VARS __should__ not be used any longer.
    : : : [/red]
    : : : [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    : : : url--> http://mark.space.servehttp.com
    : : :
    : : :
    : :
    : : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    : :
    : :
    :
    : [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    : url--> http://mark.space.servehttp.com
    :
    :

    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

Sign In or Register to comment.