php script question somewhat simple i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xroox
Forum Newbie
Posts: 1
Joined: Tue Nov 03, 2009 6:29 pm

php script question somewhat simple i think

Post by xroox »

Hi just need a quick look at this code... (s'il vous plait), and question is two parted.

using a login form script that looks like this

<?php $passwords = array("name1"=>"pass1",
"name2"=>"pass2");

if ($password == $passwords[$username]){
setcookie("username", $username, time()+1200);
echo "<H2>Access granted.</H2>";
}else{
setcookie("username", "", time()-3600);
echo "<H2>Invalid user name or password: access denied.</H2>";
}
?>

Now I should point out... firefox 'view source' shows this part of the code in pink (the first bit):

<?php $passwords = array("name1"=>

Now the issue is that instead of just showing the output "Access granted." or "Invalid user name or password: access denied.", it shows this on the .php page:

"pass1", "name2"=>"pass2"); if ($password == $passwords[$username]){ setcookie("username", $username, time()+1200); echo "
Access granted.
"; }else{ setcookie("username", "", time()-3600); echo "
Invalid user name or password: access denied.
"; } ?>

which is, everything other than the pink stuff at the beginning... so I imagine something is wrong at that point. If someone could tell me how to fix that up that would be great.

The second question would be, can I change the output to actually be a whole web page instead of just "Access granted." or "Invalid user name or password: access denied."? If someone could show me what I might want to put to have the script head to a new .html file instead of spitting out that text that would be great, thanks.

Thank you in advance ( promise to say thanks after as well :)

Here is a screenshot to show what I mean quickly... shows the .php code and the result on the page.
Attachments
screenshot
screenshot
Picture 3.jpg (148.7 KiB) Viewed 124 times
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: php script question somewhat simple i think

Post by Eric! »

Either that isn't the full script or your server is not running php. Is there nothing before the <?php $passwords... part? If there is please post the full script using [syntax=php]paste code here[/syntax] tags.

Otherwise I would say your server isn't running php. Does phpinfo() work?
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: php script question somewhat simple i think

Post by mischievous »

looks like your accessing the file directly... try installing

http://www.apachefriends.org/en/xampp-macosx.html


see if that works...
Post Reply