Like SystemiConnectFri 15 Oct 2021, 04:50
Auto Save MessagesLGforumFri 26 Feb 2021, 13:31
New tutorial questionTheCrowMon 15 Feb 2021, 08:12
Support iOS Emojis (and other platforms)LGforumSun 14 Feb 2021, 01:25
LGforum (2806)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Mr.Easybb (1587)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Bloodbath (745)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Rukiafan (533)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Dom (513)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
puppycheese (446)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
pedro (330)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Neymar (301)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Hitsu (281)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 
Flora (275)
Protected File PHP Vote_lcapProtected File PHP Voting_barProtected File PHP Vote_rcap 


Protected File PHP

HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Sat 13 Sep 2014, 02:01
So I make a Coding Tutorial at my server, but not anyone can access it, because it's protected by some password. They will be redirected in some page named passwordinput.php instead of codingtutorial.php. Then if the password is the correct one, they will be redirected into the codingtutorial.php page, but if the password is the incorrect one, some alert shows 'Incorrect password. Remember that password is case-sensitive'.

And I've tried to work with $_get now, but still, no work.

The code looks like this :

Code:
<?php
$password = $_GET['password'];
if ($password != 'pass' {
header ('Location : /codingtutorial.php');
}
else {
$popup = "Incorrect password. Remember that password is case-sensitive."
echo '<script type=text/javascript>alert('$popup');</script>'
}
Mr.EasybbMr.Easybb
Status : Love this site, that's why I'm back each day again... lol Samantha's co-owner now. Well deserved!

Posts : 1587
Join date : 2013-01-04
Sat 13 Sep 2014, 02:44
You'll need to use [ic]$_POST[/ic]


This will be codingtutorial.php
Code:
[panda=js]<?php
  session_start();
  if( !isset($_SESSION['password'] ){
      header('Location: login.php');
    }
?>
<!DOCTYPE>
<html>
<head>
</head>
<body>
  HELLO WORLD
</body>
</html>

This will be login.php

Code:
[panda=js]<?php
  session_start();
  if( isset($_SESSION['password'] ){
    $password = preg_replace('#a-zA-Z0-9#','',$_SESSION['password']); 
    }elseif( isset($_POST['password']) ){
      $password = preg_replace('#a-zA-Z0-9#','',$_POST['password']);
    }

  if($password == "YOUR PASSWORD"){
          $_SESSION['password'] = $password;
          header('Location: codingtutorial.php');
      }
?>
<!DOCTYPE>
<html>
<head>
</head>
<body>
  <form action="login.php" method="POST">
      <input type="password" name="password" placeholder="Enter Password to view Code">
      <input type="submit" value="Submit">
  </form>
 </body>
</html>

That I believe should work for you there.
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Sat 13 Sep 2014, 04:46
Thanks a lot Mr EasyBB ^^ It works. Anyway, I just figured to set a cookie after the user enters the page. So when the user enters the codingtutorial.php and enters the correct password, they redirected into the codingtutorial.php. When that thing happens, I set some cookie that the user doesn't have to enters the password anymore. But off course the cookie will expire 1 day after the user put the correct password.

Okay, based on your code, the code looks like this :

Code:
<?php
  session_start();
  if( isset($_SESSION['password'] ){
    $password = preg_replace('#a-zA-Z0-9#','',$_SESSION['password']); 
    }elseif( isset($_POST['password']) ){
      $password = preg_replace('#a-zA-Z0-9#','',$_POST['password']);
    }
  if($password == "YOUR PASSWORD"){
          $_SESSION['password'] = $password;
          header('Location: codingtutorial.php');
          $value = 'MYSTUFFS';
          setcookie("pass", $value, time()+3600);
      }
?>

Thanks again.
Mr.EasybbMr.Easybb
Status : Love this site, that's why I'm back each day again... lol Samantha's co-owner now. Well deserved!

Posts : 1587
Join date : 2013-01-04
Sat 13 Sep 2014, 17:57
You'll need to change the whole session bit to check for cookie.

Code:
[panda=js]if(isset($_COOKIE['pass']) ) {...

Then use any where that says [ic]$_SESSION[/ic] to [ic]$_COOKIE[/ic]

It'll work, session is same thing as cookie in a way that so long as the window is open they won't need the password, but a cookie I can close the window and then go back and it'll be ok. So yes you can use cookie I just used session for simplicity for myself.

You can also generate multiple passwords to use in a database. Another good thing about this is we can make a page that can only be seen once by a user with a certain password, it'll delete the password after using it. But that's a whole different story haha
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Wed 17 Sep 2014, 14:00
Lol ok thank you very much for your answer. =))

And may I ask some question? Since I'm newbie with PHP and such, yep. u_u What's the difference between session and cookie?
Mr.EasybbMr.Easybb
Status : Love this site, that's why I'm back each day again... lol Samantha's co-owner now. Well deserved!

Posts : 1587
Join date : 2013-01-04
Wed 17 Sep 2014, 18:03
Session last for the current session of the browser
Cookies last for a preset time that we define or that the user defines per the browsers scope. Both have their flaws due to the users interaction and accessibility to change these parameters, so some ways around this is to store your value in a mySQL database and delete when your datetimes match up.
BloodbathBloodbath
Status : No status yet...

Posts : 745
Join date : 2013-05-31
Age : 28
Wed 17 Sep 2014, 19:49
Generating premade passwords for specific users sounds very appealing to me, would you want me to create a draft for you, Hitsu?
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Fri 19 Sep 2014, 05:56
Okay thank you very much for your answer Easy ^^ and Bloodbath, okay, if you say so. c:
avatarGuest
Thu 05 May 2016, 05:48
Solved and archived.
Sponsored content