Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    can a php file password be in a different file location

    Hi All,

    I moved the question below as I thought I was wrong to continue in a different post which was actually a different question.

    This is a follow on question regarding a password.

    The code below is a slight revision of the original posted question to include a user name and password previously discussed.

    My question now is. Can the 'Username' word 'Tom' be stored in a different php file on the server and be read by the code below by adding some kind of $ var where the word Tom shows now and have that take the name Tom from the other stored php file.

    Something like this.....

    Code:
    <?php
    
    $whatever = (anotherfile.php)
    
    if ($_POST['Username'] == ($whatever))
    {
    # initialise variables
    ...... all the other stuff below ......
    and if it is possible and the file was in a different folder location on same server as the protected file, is a full file path required like the domain name / folder / folder / anotherfile.php

    Hope that make some kind of sense.


    Code:
    <?php
    // Define your username and password lower down
    if ($_POST['Username'] == "Tom")
    {
    # initialise variables
    $something = "";
    $data = array();
    $changed = false;
    $myTextFile = $_POST['FileName'];
    if (file_exists($myTextFile))
    $data = parse_ini_file($myTextFile, true);
    if(isset($_POST[userdata]) && $_POST[password] == "qwerty")
    {
    $data[$_POST['']]['something'] = $_POST['something'];
    $changed = true;
    }
    if ($changed) {
    $fp = fopen($myTextFile, 'w');
    ksort($data);
    foreach ($data as $key=>$dataArray){
    foreach ($dataArray as $k => $v){fwrite($fp, "$v\n");}}
    fclose($fp);
    }
    }
    ?>

    Martin.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    yes.

    anotherfile.php:

    PHP Code:
    <?PHP
    define
    ("USERNAME""Tom");
    ?>
    yourfile.php:

    PHP Code:
    include ("anotherfile.php");

    if (
    $_POST['Username'] == USERNAME)
    {
    # initialise variables
    ...... all the other stuff below ...... 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi Arcticwarrio,

    Thanks for that information.

    Additional questions.

    Is the use of UPPER case as in your example a requirement in the places you used upper case.

    Also. If the 'anotherfile.php' was a remote file not in the same folder location as the file that uses the password. Does the file which uses the password require a path as in foldername/foldername/anotherfile.php or a ../../anotherfile.php if the file is backwards in relation to the using file. I ask this as there may be more than one file using the same password located in different places.

    Martin.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    yes it requires a path from the page its used on.

    CAPS is just a reminder that its a DEFINED name not a $variable
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •