princeo Posted August 27, 2007 Share Posted August 27, 2007 iam new to php and i believe its a great tool in doing this, I have a username and a password on my home page. what i want to do is have a predefined username and password to direct to a particular page. i dont want to get db involved in this. in other words i want to password a particular page from every body except the people i want them to have the username and password. can anyone give an understandable tutorial in achieving this? i will so much appreciate it. Prince Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/ Share on other sites More sharing options...
nathanmaxsonadil Posted August 27, 2007 Share Posted August 27, 2007 somthing like this? if($_GET['password'] == '1password') { $_SESSION['loggedin'] == true; $_SESSION['password'] == '1'; header('Location: http://yoursite.com/1link.php'); }else if($_GET['password'] == '2password') { $_SESSION['loggedin'] == true; $_SESSION['password'] == '2'; header('Location: http://yoursite.com/2link.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-335253 Share on other sites More sharing options...
princeo Posted August 27, 2007 Author Share Posted August 27, 2007 Thanks for the code, but u never mentioned which page to insert the code and what i should modify in the code. remember i told u iam new to php. i would most appreciate if u take out ur valuable time and teach me as a novice. thanks Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-335292 Share on other sites More sharing options...
nathanmaxsonadil Posted August 27, 2007 Share Posted August 27, 2007 you could have a page like loginp.php with the code <?php session_start(); if($_GET['password'] == '1password') { $_SESSION['loggedin'] == true; $_SESSION['password'] == '1'; header('Location: http://yoursite.com/1link.php'); }else if($_GET['password'] == '2password') { $_SESSION['loggedin'] == true; $_SESSION['password'] == '2'; header('Location: http://yoursite.com/2link.php'); }else header('Location: htttp://yousite.com'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-335332 Share on other sites More sharing options...
princeo Posted August 28, 2007 Author Share Posted August 28, 2007 I modified the code and placed it into the body of a page i named information.php, this is the code <?php session_start(); if($_GET['password'] == '1password') { $_SESSION['loggedin'] == zane; $_SESSION['password'] == 'zane'; header('Location: http://zanedesignsltd.com/information.php'); }else if($_GET['password'] == '2password') { $_SESSION['loggedin'] == zane; $_SESSION['password'] == 'zane'; header('Location: http://zanedesignsltd.com/information.php'); }else header('Location: htttp://zanedesignsltd'); } ?> when i log in it displays this following message, pls i still need your help Parse error: syntax error, unexpected '}' in /home/zanedesi/public_html/information.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336018 Share on other sites More sharing options...
ReDucTor Posted August 28, 2007 Share Posted August 28, 2007 1. Strings need to be quoted $_SESSION['loggedin'] = 'zane'; 2. To set values use a single equals sign, to test values use double 3. Your missing a { after the else 4. Your url had htttp and didnt have .com 5. By the sounds of it its in the middle of the page by the error line you said, your going to get header() errors, so put this at the top of the file. <?php session_start(); if($_GET['password'] == '1password') { $_SESSION['loggedin'] = 'zane'; $_SESSION['password'] = 'zane'; header('Location: http://zanedesignsltd.com/information.php'); }else if($_GET['password'] == '2password') { $_SESSION['loggedin'] = 'zane'; $_SESSION['password'] = 'zane'; header('Location: http://zanedesignsltd.com/information.php'); }else { header('Location: http://zanedesignsltd.com'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336021 Share on other sites More sharing options...
princeo Posted August 28, 2007 Author Share Posted August 28, 2007 it actually went to the page specified but it displayed with the following information, what do i do again? please explain to me as a novice. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/zanedesi/public_html/information.php:9) in /home/zanedesi/public_html/information.php on line 10 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/zanedesi/public_html/information.php:9) in /home/zanedesi/public_html/information.php on line 10 Warning: Cannot modify header information - headers already sent by (output started at /home/zanedesi/public_html/information.php:9) in /home/zanedesi/public_html/information.php on line 20 Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336031 Share on other sites More sharing options...
ReDucTor Posted August 28, 2007 Share Posted August 28, 2007 the code must be at the VERY top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336034 Share on other sites More sharing options...
princeo Posted August 28, 2007 Author Share Posted August 28, 2007 iam using dreamweaver, where exactly should i put the code? Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336037 Share on other sites More sharing options...
princeo Posted August 28, 2007 Author Share Posted August 28, 2007 It keep on showing these two errors. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/zanedesi/public_html/information.php:3) in /home/zanedesi/public_html/information.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /home/zanedesi/public_html/information.php:3) in /home/zanedesi/public_html/information.php on line 14 this is what is on line 4 session_start(); then line 14 header('Location: http://zanedesignsltd.com'); iam sorry bothering you, i desperately need to solve this issue urgently. Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336180 Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Just a tip: Don't use dreamweaver - you need to learn what the code is doing and if it's doing it for you you won't understand. What is on lines 1-3? Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-336183 Share on other sites More sharing options...
princeo Posted August 29, 2007 Author Share Posted August 29, 2007 the code must be at the VERY top of the page. I have been very happy with your supports but this thing is still giving a hell of headache, check out my last post and help me out please. Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-337045 Share on other sites More sharing options...
nathanmaxsonadil Posted August 29, 2007 Share Posted August 29, 2007 What is on lines 1-3? Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-337327 Share on other sites More sharing options...
princeo Posted August 30, 2007 Author Share Posted August 30, 2007 This is actually what shows up Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/zanedesi/public_html/information.php:2) in /home/zanedesi/public_html/information.php on line 3 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/zanedesi/public_html/information.php:2) in /home/zanedesi/public_html/information.php on line 3 Warning: Cannot modify header information - headers already sent by (output started at /home/zanedesi/public_html/information.php:2) in /home/zanedesi/public_html/information.php on line 13 This the code according to how it appears in dreamweaver 1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2. <?php 3. session_start(); 4. if($_GET['password'] == '1password') { 5. $_SESSION['loggedin'] = 'zane'; 6. $_SESSION['password'] = 'zane'; 7. header('Location: http://zanedesignsltd.com/information.php'); 8. }else if($_GET['password'] == '2password') { 9. $_SESSION['loggedin'] = 'zane'; 10. $_SESSION['password'] = 'zane'; 11. header('Location: http://zanedesignsltd.com/information.php'); 12. }else { 13. header('Location: http://zanedesignsltd.com'); 14. } ?15. > Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-337797 Share on other sites More sharing options...
nathanmaxsonadil Posted August 30, 2007 Share Posted August 30, 2007 the problem is that you have this 1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> on top Quote Link to comment https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/#findComment-337871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.