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!
I stored username and password of vistors i wanted to view some pages in my website in an associative array but I having problem getting it work that is to check if the value inputed in the login form matches an element in the array so as to grant the user access to the site but i am not able to get the exact script to do that and i need help for this below is the script;
Remove the foreach loop. In an if, use the function and check the value of the element when it exists. If the element's value matches the input, it was correct.
Can somebody help me on a script to make it work that is to check if the datas inputed from the form i.e the username and the password field matches an element in the array because i am finding difficulties using array_key_exist()
I told you how to do it. Instead of hoping that someone will code it for you, why not post what you tried to build that is detailed by the solution I provided?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
below is what I tried;
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by magosla2001 on Mon Sep 04, 2006 12:00 pm, edited 1 time in total.
Single quotes are string literals. You're requesting the function to search for the literal "$un" not the contents of the variable.
After correcting that you'll need to check that the value of that element matches the password submitted before finally redirecting.
As a side note, make sure to use full URIs/URLs in header() based redirections. Web servers and web browsers that only implement the HTTP standards strictly will be unable to use relative redirections.
I belive I am lost in this because this script is unable to check if the username field exist in as a key in the array. And I also dont know how to go about checking if the key value matches the password field. I tried checking if the username field matched the an array key but it doesn't work this was the little changes i made to the script;