Jump to content

eawf

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    Tacoma, WA

eawf's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. BUT, the first snippet isn't working at all and the second one is.
  2. Is the answer that you can't escape out of a foreach() loop with the header() function?
  3. One way would be: $rows = @file("/path/to/filename.ext"); foreach($rows as $key=>$value){ $row = $key+1; echo $value." line ".$row."<br />"; }
  4. No. The issue is that this (psuedo) code doesn't work: $rows[ ] = "eawf:otherstuff\n"; $testdata = "eawf"; foreach($rows as $row){ $data = explode(":",$row); if($data[0] == $testdata){ header("Location: $self"); } } while this one does work: $rows[ ] = "eawf:otherstuff\n"; $testdata = "eawf"; foreach($rows as $row){ $data = explode(":",$row); if($data[0] == $testdata){ $flag = true } } if(isset($flag)){ header("Location: $self"); } actually does work. So the question is, WHY doesn't the first code snippet work? The psuedo code for the above is: Form submit provides input vars for userid and password. read all records from .htpasswd and load to an array ($rows) process array one element at a time parse array vars via ":" character. if userid from form matches the userid from .htpassword: reload the page with a get var loaded with an error message. else process next record. I can[t find anything online indicating that the foreach loop is not able to be broken by issuing the header() function, which, at least to my way of thinking, should stop program code execution by simply reloading the page again. What ends up happening is that the program continues to run and the header statement is not executed. Hope this makes sense?
  5. Am I missing something. The if statement is exactly the same. Shouldn't the condition being true kick in the header statement which would reload the page with the error message passed in the get? Yeah, I checked that previously to verify that headers weren't being sent, and they're not, PLUS that doesn't explain why the header statement works below the foreach loop, right? I till try again with the settings turned on to see if there's something generated.
  6. Code produces no error messages in the log or on screen. The if condition passes as if it returns false. Note that the same if condition passes as true on the first bit of code. IOW: header() statement works as expected in the first code and doesn't work at all in the second snippet.
  7. I have an administrative back end on a secure server that I want to use Basic Authentication for. In my "Add" module, I can't figure out why this works: $rows = file($passfile); import_request_variables("gp","x_"); switch($x_action){ case "Add": ... foreach($rows as $row){ $data = explode(":",$row); if($x_userid == $data[0]){ $dupe = 1; $errormsg = "Duplicate Record!"; } } ... if($dupe == 0){ write_rows($passfile,$rows); header("Location: $self"); }else{ header("Location: $self?errormsg=$errormsg"); } break; ... and this doesn't: $rows = file($passfile); import_request_variables("gp","x_"); switch($x_action){ case "Add": ... foreach($rows as $row){ $data = explode(":",$row); if($x_userid == $data[0]){ header("Location: $self?errormsg=Duplicate Record!"); } } ... break; Thanks in advance for your constructive comments.
  8. Check your Error Logs for the actual PHP error. Also, instead of writing the connect code, use Justin Vincent's ez_SQL database wrapper. Makes database interactions rediculously simple. [!--quoteo(post=382122:date=Jun 10 2006, 01:30 AM:name=PC-SandMan^^)--][div class=\'quotetop\']QUOTE(PC-SandMan^^ @ Jun 10 2006, 01:30 AM) [snapback]382122[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hi I've installed Postgre for first time and tried to connect php <?php echo "1"; pg_connect("host=localhost ..."); echo "2"; ?> I was expecting an error on the connection string maybe but all I got was 1 ... I tried several times with different connection strings ... and aways php stoped on pg_connect help ? thx [/quote]
  9. Check out Justin Vincents "ez_sql" database wrapper class, modify it for PostgreSQL(only takes a couple lines), and then check out how it all works. It will ultimately save you LOTS of headaches, and database can be anywhere, ssl or not. HTH!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.