-
Posts
20 -
Joined
-
Last visited
About thunder708
- Birthday 11/01/1990
Profile Information
-
Gender
Male
-
Location
England
thunder708's Achievements
Newbie (1/5)
0
Reputation
-
i have figured out what i have done wrong, i had changed your code to say foreach ($users as $u) { and changed the users file to say $users[0]["name"]='liam'; $users[0]["pass"]='lol'; but forgot to change the declaration to $users = array(); it was still $user = array(); my bad thank you anyway
-
$user = $_REQUEST['user']; // requests user from form $pass = $_REQUEST['pass']; // requests pass from form include("users.php"); foreach ($users as $u) { if ($u['name'] == $user && $u['pass'] == $pass) { echo "well don eyou have logged in "; } }
-
thanks, this works if i put the contents of users.php into the main file but doesnt work if i include the file... any ideas?
-
hi all! right i have two files, login.php and users.php. users.php <? $user = array(); // Set Users $user[0]["name"]='liam'; $user[0]["pass"]='lol'; $user[1]["name"]='mike'; $user[1]["pass"]='rofl'; ?> and in the login.php i have a form that you type in a user and pass and it logs you in, i know how to do this if i set the values within the login file itself but i want to be able to use this array i have made. so my question is, how do i search the array for the required user and pass when it is submitted from the form?
-
i got my else in the wrong place cant believe i didnt notice that lol <? session_start(); if(!session_is_registered(admin)){ $a=1;} function login($pass) { $pass = $_REQUEST['pass']; if($pass == 'mypass'){ session_start(); session_register(admin); header('location:media2.php'); echo "success!"; } else { $data = 'Wrong Password'; return $data; }} /* ?> <LINK href="style.css" rel="stylesheet" type="text/css"> <? */ $do = $_REQUEST['do']; $pass = $_REQUEST['pass']; if($a==1){ ?> Please Provide Your Password to gain Access<br> <form action="media2.php?do=login" method="post"> <input type="hidden" value="1" name="1"> <input type="password" name="pass"><input type="submit" value="login"> </form> <? if ($do == "login") { login($pass); } } else { if ($do == "cd") { cd(); } elseif ($do == "dvd") { cd(); } elseif ($do == "games") { cd(); } echo "<a href='?do=cd'>Cd</a> | <a href='?do=games'>Games</a> | <a href='?do=dvd'>DVD</a>"; } function cd() { echo "CD"; } function dvd() { $data = 'dvd'; return $data; } function games() { $data = 'games'; return $data; } thanks for all help though
-
i think i know where i have gone wrong....ill let you know once ive figured it out
-
sorry for delay i have been at college heres the code i have attempted and its not working and i know i have // before the stylesheet btw <? session_start(); if(!session_is_registered(admin)){ $a=1;} /* ?> <LINK href="style.css" rel="stylesheet" type="text/css"> <? */ if($a==1){ ?> Please Provide Your Password to gain Access<br> <form action="media.php?do=login" method="post"> <input type="hidden" value="1" name="1"> <input type="password" name="pass"><input type="submit" value="login"> </form> <? } else { $do = $_REQUEST['do']; $pass = $_REQUEST['pass']; if ($do == "login") { login($pass); } if ($do == "cd") { cd(); } elseif ($do == "dvd") { cd(); } elseif ($do == "games") { cd(); } echo "<a href='?do=cd'>Cd</a> | <a href='?do=games'>Games</a> | <a href='?do=dvd'>DVD</a>"; } function login($pass) { session_start(); if($pass == 'mypass'){ session_register('admin'); header('location:media.php'); } else { $data = 'Wrong Password'; return $data; } } function cd() { echo "CD"; } function dvd() { $data = 'dvd'; return $data; } function games() { $data = 'games'; return $data; } i even bypassed the login just to test out the other functions but when clicking on the link it doesnt show anything
-
i know how to do a login script, this script works if i refer it to a seperate page instead of using it as a function but i dont want that, i want it all on one page as i cant be doing with multiple pages for a simple application of php. i wouldnt be asking for help on a scripting forum if i could find it in a tutorial would i? if you can find me a suitable tutorial that uses form data and functions, be my guest.
-
sorry didnt want to make new thread cos its same code casuing the problem.... also, the password isnt being transferred to the login() function. the form action should be media.php?do=login, i have altered this in my code before anyone says anything any ideas?
-
never mind......found it lol Thank you for pointing it out tho =D
-
if its this bit $pass = $_POST[pass]; when i try $pass = $_POST['pass']; i get error : unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
-
i keep getting the error: unexpected $end on line 56 which is the last line of my code, i have thoroughly checked otu the code makign sure all { having matching } but cant explain why i get this error. here is my code: <? session_start(); if(!session_is_registered(admin)){ $a=1;} ?> <LINK href="style.css" rel="stylesheet" type="text/css"> <? if($a==1){ ?> Please Provide Your Password to gain Access<br> <form action="media?do=login" method="post"> <input type="hidden" value="1" name="1"> <input type="password" name="pass"><input type="submit" value="login"> </form> <? } else { $do = $_REQUEST['do']; if ($do == "login") { login(); } elseif ($do == "cd") { cd(); } elseif ($do == "dvd") { cd(); } elseif ($do == "games") { cd(); } echo "<a href='?do=cd'>Cd</a> | <a href='?do=games'>Games</a> | <a href='?do=dvd'>DVD</a> | } function login() { $pass = $_POST[pass]; if($pass == 'mypass'){ session_register('admin'); header('location:media.php'); } else { $data = 'Wrong Password'; return $data; } } function cd() { $data = 'cd'; return $data; } function dvd() { $data = 'dvd'; return $data; } function games() { $data = 'games'; return $data; } any ideas?
-
just look at my last post ive edited it and tested it out on my own website and it works and btw either way that i have suggested works
-
Thank you for this help, i cant believe how stupid i was i missed out the ASC and DESC much thanks!
-
$_SERVER['SERVER_NAME'] = $_SERVER['SERVER_NAME']."/"; Try that my two previous attempts didnt work, if you saw it. it should but you could just have it as: $server = $_SERVER['SERVER_NAME']."/"; just to save typing time