Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/66860-new-to-php-help-about-page-passwod/
Share on other sites

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');
}

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');
}
?>

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

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');
}
?>

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

 

 

 

 

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.

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. >

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.