Results 1 to 17 of 17

Thread: Files not opened

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Files not opened

    Hi All,

    I have some errors regarding files that I have just uploaded to the server, but I can't figure out where the errors are. The error and warning I am getting are pasted below. But I uploaded all the files. Is there something that I am doing wrong?


    Warning: require_once(__DIR__idiorm.php) [function.require-once]: failed to open stream: No such file or directory in /usr/local/apache2/htdocs/demo/includes/main.php on line 7

    Fatal error: require_once() [function.require]: Failed opening required '__DIR__idiorm.php' (include_path='.:../PEAR-1.1') in /usr/local/apache2/htdocs/demo/includes/main.php on line 7


    Can someone tell me what to do here, please?

    I will appreciate your help.

    Thanks.

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    Post your code. I don't use PHP much anymore, but it looks like your code might be trying to open a file with the physical __DIR__ in the filename (hence why it is saying it cannot find the file).
    It all depends on how you're concatenating the information in your code.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by kfcSmitty View Post
    Post your code. I don't use PHP much anymore, but it looks like your code might be trying to open a file with the physical __DIR__ in the filename (hence why it is saying it cannot find the file).
    It all depends on how you're concatenating the information in your code.
    Thanks for your response to my post. The file are very many. I got them from a tutorial on the net about how to create a user register/Sign up/LOGIN page. However, this is the code for the page that gave me the error and warning messages.
    [QUOTE]

    <?php

    require_once 'includes/main.php';


    /*--------------------------------------------------
    Handle visits with a login token. If it is
    valid, log the person in.
    ---------------------------------------------------*/


    if(isset($_GET['tkn'])){

    // Is this a valid login token?
    $user = User::findByToken($_GET['tkn']);

    if($user){

    // Yes! Login the user and redirect to the protected page.

    $user->login();
    redirect('protected.php');
    }

    // Invalid token. Redirect back to the login form.
    redirect('index.php');
    }



    /*--------------------------------------------------
    Handle logging out of the system. The logout
    link in protected.php leads here.
    ---------------------------------------------------*/


    if(isset($_GET['logout'])){

    $user = new User();

    if($user->loggedIn()){
    $user->logout();
    }

    redirect('index.php');
    }


    /*--------------------------------------------------
    Don't show the login page to already
    logged-in users.
    ---------------------------------------------------*/


    $user = new User();

    if($user->loggedIn()){
    redirect('protected.php');
    }



    /*--------------------------------------------------
    Handle submitting the login form via AJAX
    ---------------------------------------------------*/


    try{

    if(!empty($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH'])){

    // Output a JSON header

    header('Content-type: application/json');

    // Is the email address valid?

    if(!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
    throw new Exception('Please enter a valid email.');
    }

    // This will throw an exception if the person is above
    // the allowed login attempt limits (see functions.php for more):
    rate_limit($_SERVER['REMOTE_ADDR']);

    // Record this login attempt
    rate_limit_tick($_SERVER['REMOTE_ADDR'], $_POST['email']);

    // Send the message to the user

    $message = '';
    $email = $_POST['email'];
    $subject = 'Your Login Link';

    if(!User::exists($email)){
    $subject = "Thank You For Registering!";
    $message = "Thank you for registering at our site!\n\n";
    }

    // Attempt to login or register the person
    $user = User::loginOrRegister($_POST['email']);


    $message.= "You can login from this URL:\n";
    $message.= get_page_url()."?tkn=".$user->generateToken()."\n\n";

    $message.= "The link is going expire automatically after 10 minutes.";

    $result = send_email($fromEmail, $_POST['email'], $subject, $message);

    if(!$result){
    throw new Exception("There was an error sending your email. Please try again.");
    }

    die(json_encode(array(
    'message' => 'Thank you! We\'ve sent a link to your inbox. Check your spam folder as well.'
    )));
    }
    }
    catch(Exception $e){

    die(json_encode(array(
    'error'=>1,
    'message' => $e->getMessage()
    )));
    }

    /*--------------------------------------------------
    Output the login form
    ---------------------------------------------------*/

    ?>

    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="utf-8"/>
    <title>Tutorial: Super Simple Registration System With PHP &amp; MySQL</title>

    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet">

    <!-- The main CSS file -->
    <link href="assets/css/style.css" rel="stylesheet" />

    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    </head>

    <body>

    <form id="login-register" method="post" action="index.php">

    <h1>Login or Register</h1>

    <input type="text" placeholder="your@email.com" name="email" autofocus />
    <p>Enter your email address above and we will send <br />you a login link.</p>

    <button type="submit">Login / Register</button>

    <span></span>

    </form>

    <footer>
    <a class="tz" href="http://tutorialzine.com/2013/08/simple-registration-system-php-mysql/">Super Simple Registration System</a>
    <div id="tzine-actions"></div>
    <span class="close"></span>
    </footer>

    <!-- JavaScript Includes -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="assets/js/script.js"></script>

    </body>
    </html>

    [QUOTE]

    Hope that helps.
    Menre

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    The error you've posted is for your includes/main.php file, is that the file you've posted?

    If it is, then your require_once will not work, because:

    #1 You're including itself, which is redunant.
    #2 You're not including itself properly. You're saying to go to includes/includes/main.php instead of includes/main.php.

    If this is not your main.php code, please post it.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by kfcSmitty View Post
    The error you've posted is for your includes/main.php file, is that the file you've posted?

    If it is, then your require_once will not work, because:

    #1 You're including itself, which is redunant.
    #2 You're not including itself properly. You're saying to go to includes/includes/main.php instead of includes/main.php.

    If this is not your main.php code, please post it.
    Hello,
    As always your reply was much appreciated. That was not actually the main.php file that I sent before. I am sending you the main.php file now please.
    [QUOTE]
    <?php

    /**
    * Include the libraries
    */

    require_once __DIR__."/idiorm.php";
    require_once __DIR__."/User.class.php";
    require_once __DIR__."/functions.php";

    /**
    * Configure Idiorm
    */

    $db_host = 'the_server';
    $db_name = 'the_database_names';
    $db_user = 'the_user';
    $db_pass = 'the_password';

    ORM::configure("mysql:host=$db_host;dbname=$db_name");
    ORM::configure("username", $db_user);
    ORM::configure("password", $db_pass);

    // Set the database connection to UTF-8
    ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));

    /**
    * Configure the session
    */

    session_name('tzreg');

    // Uncomment to keep people logged in for a week
    // session_set_cookie_params(60 * 60 * 24 * 7);

    session_start();

    /**
    * Other settings
    */

    // The "from" email address that is used in the emails that are sent to users.
    // Some hosting providers block outgoing email if this address
    // is not registered as a real email account on their system, so put a real one here.

    $fromEmail = 'info@company.com';

    if(!$fromEmail){
    // This is only used if you haven't filled an email address in $fromEmail
    $fromEmail = 'noreply@'.$_SERVER['SERVER_NAME'];
    }

    [QUOTE]

    With kind regards,
    Menre

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    I don't see anything glaringly wrong with the code. Are you sure your idiorm.php file is in the same folder as your main.php file?

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,535

    Re: Files not opened

    The online PHP document has this to say about __DIR__
    Quote Originally Posted by php.net
    __DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)
    http://php.net/manual/en/language.co...predefined.php

    I think the key may be in that last bit:
    Added in PHP 5.3.0.


    Do you know what version of PHP you're running?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by kfcSmitty View Post
    I don't see anything glaringly wrong with the code. Are you sure your idiorm.php file is in the same folder as your main.php file?
    Yes, the two files are in the same folder.

    I ckecked the version of PHP that my server is using and it shows 'PHP Version 5.2.9'. Which means, it may not be the right one. How can I correct this error it is driving me mad please?

    I have added the original ZIP File with all the files to this post please? Like I mentioned earlier, I got the code from a tutorial. I have checked the ZIP file and it has no viruses in it please.

    I will appreciate your further help.

    Thanks,
    Menre
    Attached Files Attached Files

  9. #9
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    As techgnome said, you need PHP 5.3 to run __DIR__. If you want the same functionality, you'll need to replace "__DIR__" with "dirname(__FILE__)".

    However, if it is possible, I would definitely recommend upgrading to a higher version of PHP. PHP 5.3 was released back in 2010, so you're fairly far behind.

    However, depending on how much you have running on PHP 5.2.9, you may also get some errors during the upgrade.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by kfcSmitty View Post
    As techgnome said, you need PHP 5.3 to run __DIR__. If you want the same functionality, you'll need to replace "__DIR__" with "dirname(__FILE__)".

    However, if it is possible, I would definitely recommend upgrading to a higher version of PHP. PHP 5.3 was released back in 2010, so you're fairly far behind.

    However, depending on how much you have running on PHP 5.2.9, you may also get some errors during the upgrade.
    Thanks for your quick response. I pay for my shared hosting server and the company happens to be using old technologies for its shared hosting customers. I would have loved to upgrade, but I have no much control over their server.

    When you say "you'll need to replace "__DIR__" with "dirname(__FILE__)". I an kind of confused. What exactly do you mean by that please? Looking at my previous code of the attachment, how do I do that?

    Will mostly appreciate your help.

    Thanks

  11. #11
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    In the second code snippet you posted, you posted this code

    PHP Code:
    require_once __DIR__."/idiorm.php";
    require_once 
    __DIR__."/User.class.php";
    require_once 
    __DIR__."/functions.php"
    Change it to

    PHP Code:
    require_once dirname(__FILE__) . "/idiorm.php";
    require_once 
    dirname(__FILE__) . "/User.class.php";
    require_once 
    dirname(__FILE__) . "/functions.php"

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by kfcSmitty View Post
    In the second code snippet you posted, you posted this code

    PHP Code:
    require_once __DIR__."/idiorm.php";
    require_once 
    __DIR__."/User.class.php";
    require_once 
    __DIR__."/functions.php"
    Change it to

    PHP Code:
    require_once dirname(__FILE__) . "/idiorm.php";
    require_once 
    dirname(__FILE__) . "/User.class.php";
    require_once 
    dirname(__FILE__) . "/functions.php"
    Hello Again,

    Thanks for the suggestion. I tried it but got another error message which is posted below.

    "Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in /usr/local/apache2/htdocs/test/includes/main.php on line 25"

    Any other suggestions please?

    Thanks,

  13. #13
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    If the code you've grabbed has __DIR__ in it, there is a good chance it is meant to be run in PHP 5.3 and not 5.2. You're probably going to have to fix a lot of issues if you're going to convert it to run on 5.2.

  14. #14
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,535

    Re: Files not opened

    Ok.... now that is a completely new issue... the files are now being included... they're being found... now the issue is some class isn't being init properly... not sure if it's how you're using ORM ... or something in the ORM class itself.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by techgnome View Post
    Ok.... now that is a completely new issue... the files are now being included... they're being found... now the issue is some class isn't being init properly... not sure if it's how you're using ORM ... or something in the ORM class itself.


    -tg
    Hello Again,

    Thanks all for your help so far. I was actually looking for PHP/MySQL code to create a Login/Register page. Can you direct me to any good code that I can grab and use, please?

    I will really appreciate your further help.

    Thanks in advance.

  16. #16
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Files not opened

    I would recommend going through the idiorm documentation (http://idiorm.readthedocs.org/en/lat...tallation.html) and making sure you've got everything set up.

    From what I can tell, idiorm uses PDO, do you have PDO installed?

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Re: Files not opened

    Quote Originally Posted by kfcSmitty View Post
    I would recommend going through the idiorm documentation (http://idiorm.readthedocs.org/en/lat...tallation.html) and making sure you've got everything set up.

    From what I can tell, idiorm uses PDO, do you have PDO installed?
    Thanks again I haven't got PDO installed. That could certainly be anong the reasons why it is not working yet. But I will appreciate another code for the purpose of registering and logging in on a website please.

Posting Permissions

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



Click Here to Expand Forum to Full Width