PHP - Ssl And Require_once()
I was wondering how to get around the security warning that pops up when I add require_once ('includes/prochart.php') to my webpage. I edited my .htaccess file to make all pages https, but when i do this include it isn't considered a secure page so an annoying popup comes up that you have to click no on to load my content. Is there a way around this?
Similar TutorialsHi, I think I understand this but want to check. If I have files register, user.class and dbconnect. If both register and user.class use require_once dbconnect will the dbconnect still only be required on the first time? Ben im writing php application in windows 7 using apachi . iwant to include php file to another php file. This is the code. test.php ------------- before <?php require_once 'footer.php'; ?> after fotter.php -------------- test 1 ------------------------- test2 when I include the above footer.php into test.php file I got the following result. before <?php require_once 'footer.php'; ?> after Could you please tell me wher i goes woring? I'm writing a rather large script and it appears that I'm running into some require_once problems. So far I only have a few files wrote for my script.. ./includes/objects/database.class.php require_once("../../config.php"); ./test.php require_once("./config.php"); require_once("./includes/objects/database.class.php"); When I try running the test.php I get the following error: Code: [Select] Warning: require_once(../../config.inc.php) [function.require-once]: failed to open stream: No such file or directory in /includes/objects/database.class.php on line 27 Fatal error: require_once() [function.require]: Failed opening required '../../config.inc.php' (include_path='.:/opt/lampp/lib/php') in /includes/objects/database.class.php on line 27 However, when I run the database.class.php by itself it doesn't have any errors at all and it requires (sounds weird.. includes I guess?) the file just fine. I only get the above error from running test.php. I'm running on a local environment using XAMPP so there might be some php configuration option that I'm not aware of. I've tried doing some reading and I'm honestly not sure what could be the problem. Help? I have a page that was working perfectly. I decided to move that page. Once I did that, I changed my require_once statement to reflect that the page had moved. Although the paths seem correct, I am getting this error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '../../../data/MoStopsDEV/ConnectionStrings.php' (include_path='.;C:\Program Files\Jcx.Software\VS.Php\2008\php 5\pear;C:\Program Files\Jcx.Software\VS.Php\2008\') I researched this error but am not able to find anything helpful. Any ideas? I have 4 php files. 1. dbuser.php, declares class dbuser.php, no includes 2. dbobject.php, declares class dbobject.php, includes file 1. 3. casedetails.php, includes files 1 and 2 4. viewcase.php, includes files 1 and 3. When I try to run file 4, i get cannot redeclare class dbuser.php - error Even every require is followed by _once, but I still get "Cannot redeclare class dbuser"-error when running file 4. Full PHP-code below. I tried also putting "if(!class_exists('dbuser')) { ... " around class dbuser declaration but I still got the same error.. Is this a bug in PHP? I'm running version 5.x on apache 2 Thanks! 1. dbuser.php Code: [Select] <?PHP //$time = round(microtime(), 3); session_start(); require_once("settings.php"); //this is just simple array class dbuser { //Constructor function __construct($username=NULL, $password=NULL, $cookies=FALSE) { //Yhdistet��n tietokantaan ja k�ynnistet��n sessio require_once("dbconnect.php"); //Jos ei annettu parametrein� kayttajanimea ja salasanaa if (!isset($username) | !isset($password)) { //Jos salasana ja kayttaja tallennettu SESSION variableen if (isset($_SESSION['user']['email']) && $this->checkFingerprint($_SESSION['user']['fingerprint'])) { $this->logged = TRUE; foreach($_SESSION['user'] as $key => $value) { $this->$key=$value; } //Jos salasana ja kayttaja tallennettu kekseihin } elseif ( isset($_COOKIE['email']) && isset($_COOKIE['password']) ) { $this->logged = ($this->login($_COOKIE['email'], $_COOKIE['password'], FALSE, TRUE)); } //Jos annettu parametrein� knimi ja pwd } else { $this->logged = ($this->login($username, $password, $cookies, FALSE)); } //Costructor loppuu } //Kirjautuu sisaan, ottaa parametreina knimen ja pwd:n sek� tallennetaanko kekseihin, sa sen onko pwd kryptattu valmiiksi public function login($username, $password, $cookies=FALSE, $precrypted=FALSE) { global $settings; if ($precrypted) { $password = mysql_real_escape_string($password); } else { $password = sha1($password); } $username = mysql_real_escape_string($username); //MySQL query $time = time(); $loginQuery = "SELECT * FROM users WHERE email='$username' AND salasana='$password' AND aktiivinen='1' AND (vanhenee>'$time' OR vanhenee='')"; $fprint = $this->createFingerprint(); if($precrypted) { $loginQuery .= " AND fingerprint='$fprint'"; } $result = mysql_query($loginQuery) or trigger_error(mysql_error); $login = mysql_num_rows($result) or trigger_error(mysql_error()); if ($login != 1) { setcookie("email",'',-100000, "/"); setcookie("password",'',-100000, "/"); mysql_close(); session_destroy(); return FALSE; } else { $result = mysql_fetch_assoc($result); foreach ($result as $field => $value) { $this->$field=$value; $_SESSION['user'][$field] = $value; } $update = "UPDATE users SET kirjautunut='" . time() . "' WHERE id='" . $this->id . "'"; mysql_query($update) or trigger_error(mysql_error()); $update = "UPDATE users SET fingerprint='" . $fprint . "' WHERE id='" . $this->id . "'"; mysql_query($update) or trigger_error(mysql_error()); $this->kirjautunut=time(); $_SESSION['user']['kirjautunut'] = time(); if ($cookies) { setcookie("email",$username,($settings['REMEMBER_LOGIN_DURATION'] + time()), "/"); setcookie("password",$password,($settings['REMEMBER_LOGIN_DURATION'] + time()), "/"); } return TRUE; } } public function adduser($values) { if ($this->logged) { $insert = "INSERT INTO users ("; $vals = " VALUES("; $values['salasana'] = sha1($values['salasana']); foreach($values as $key => $value) { $insert .= mysql_real_escape_string($key) . ', '; $vals .= "'" . mysql_real_escape_string($value) . "', "; } $insert = substr($insert, 0, -2); $vals = substr($vals , 0, -2); $insert .= ')'; $vals .= ')'; $insert .= $vals; mysql_query($insert) or trigger_error(mysql_error()); return TRUE; } else { return FALSE; } } public function getusers($where=NULL, $order=NULL, $desc=NULL) { $query = "SELECT * FROM users"; if (isset($where)) { $query .= " WHERE "; foreach($where as $column => $value) { $query .= $column . " = '" . $value . "' AND "; } $query = substr($query, 0 ,-4); } if (isset($order)) { $query .= " ORDER BY " . $order . " "; } if (isset($desc)) { $query .= 'DESC'; } $values = mysql_query($query) or trigger_error(mysql_error()); $counter = 0; while ($row = mysql_fetch_assoc($values)) { foreach ($row as $key => $value) { $return[$counter][$key] = $value; } $counter++; } return $return; } public function update($id, $data) { $insert = "UPDATE users SET "; foreach($data as $key => $value) { $insert .= $key . '='; $insert .= "'" .$value . "', "; } $insert = substr($insert, 0, -2); $insert .= " WHERE id = '" . $id . "'" ; unset($data['id']); mysql_query($insert) or trigger_error(mysql_error()); } public function remove($id) { $rem = "DELETE FROM users WHERE id=$id LIMIT 1"; mysql_query($rem) or trigger_error(mysql_error()); } private function createFingerprint() { $print = "NJIARDL"; $print .= $_SERVER['HTTP_USER_AGENT']; $print .= $_SERVER['REMOTE_ADDR']; return md5($print); } private function checkFingerprint($real) { $print = $this->createFingerprint(); if ($real == $print) { return TRUE; } else { return FALSE; } } // Class dbuser loppuu } 2. dbobject.php Code: [Select] <?PHP //$time = round(microtime(), 3); require_once("dbuser.php"); .... lots of irrelevant code... class dbobject { .... ?> 3. Code: [Select] <?PHP require_once('../PHPcore/dbuser.php'); // this causes the error somehow... $user = new dbuser(); if(!$user->logged) { Header("Location:index.php"); } ... Lots of irrelevant code.. 4. I tried running this file when got the error... Code: [Select] <?PHP session_start(); require_once("PHPcore/dbuser.php"); $user = new dbuser(); if(!$user->logged) { Header("Location:index.php"); } require_once("views/casedetails.php"); Need help urgent. the website sudden prompt out error below: Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(/var/www/vhosts/db2020.co.uk/application/application/config/admin/config.live.php) is not within the allowed path(s): (/var/www/vhosts/db2020.co.uk/subdomains/admin/httpdocs:/tmp) in /var/www/vhosts/db2020.co.uk/subdomains/admin/httpdocs/index.php on line 11 Warning: require_once(/var/www/vhosts/db2020.co.uk/application/application/config/admin/config.live.php) [function.require-once]: failed to open stream: Operation not permitted in /var/www/vhosts/db2020.co.uk/subdomains/admin/httpdocs/index.php on line 11 Fatal error: require_once() [function.require]: Failed opening required '/var/www/vhosts/db2020.co.uk/application/application/config/admin/config.live.php' (include_path='.:') in /var/www/vhosts/db2020.co.uk/subdomains/admin/httpdocs/index.php on line 11 and also after this problem occur, trafic of this domain go overlimit. how can i solve this problem? urgent.... website = https://db2020.co.uk/ thanks. Is it possible to set the require_once, so that later in the script PHP does not require_once the file? Code: [Select] $file = $root.'filename.php'; set_require_once($file);//this would be nice require_once($file);//so this does not load Hi,
I hope someone can help. I am fairly new to php and have the following problem that I cannot get a solution for.
We are building a logon system for a website and are receiving the following error.
?>PHP Warning: require_once(classes/Config.php): failed to open stream: No such file or directory in C:\Domains\hellopoker.co.za\wwwroot\test\php\core\init.php on line 22 PHP Fatal error: require_once(): Failed opening required 'classes/Config.php' (include_path='.;C:\php\pear') in C:\Domains\hellopoker.co.za\wwwroot\test\php\core\init.php on line 22
Code for index.php
<?php require_once 'core/init.php'; echo Config::get('mysql/host'); ?> Code for config.php <?php class Config{ public static function get ($path = null){ if ($path){ $config = $GLOBALS['config']; $path = explore('/',$path); foreach($path as $bit){ if(isset($config[$bit])){ echo 'Set'; } } } } } ?> Code for init.php <?php session_start(); $GLOBALS['config'] = array( 'mysql' => array( 'mysql' => 'xxxxxxx', 'username' => 'xxxxxx', 'password' => 'xxxxxxx', 'db' => 'xxxxxxx' ), 'remember' => array( 'cookie_name' => 'hash', 'cookie_expiry' => 604800 ), 'session' => array( 'session_name' => 'user' ) ); spl_autoload_register(function($class) { require_once 'classes/' . $class . '.php'; }); ?> ?> Any help will be greatly be appreciated. I'm trying to make a simple website where people register to my website. When the user doesn't fill anything inside the boxes they get a message "Please fill all required fields" on the register.php page On my local host require_once works good. It shows up.
But when i upload the files to my sever the require_once does not show up on the register.php It just refreshes and i dont get the message "Please fill all required fields"
This is the code that works in local host but not in a live server <?php require_once 'messages.php'; ?>
Here is my full code
Register page: <html> <?php require_once 'messages.php'; ?> <br><br> <form action="register-clicked.php" method="POST"> Username:<br> <input type="text" name="usernamebox" placeholder="Enter Username Here"> <br><br> Email:<br> <input type="text" name="emailbox" placeholder="Enter email here"> <br><br> Password:<br> <input type="password" name="passwordbox" placeholder="Enter password here"> <br><br> Confirm Password:<br> <input type="password" name="passwordconfirmbox" placeholder="Re-enter password here"> <br><br> <input type="submit" name="submitbox" value="Press to submit"> <br><br> </form> </html>
Register clicked <?php session_start(); $data = $_POST; if( empty($data['usernamebox']) || empty($data['emailbox']) || empty($data['passwordbox']) || empty($data['passwordconfirmbox'])) { $_SESSION['messages'][] = 'Please fill all required fields'; header('Location: register.php'); exit; } if ($data['passwordbox'] !== $data['passwordconfirmbox']) { $_SESSION['messages'][] = 'Passwords do not match'; header('Location: register.php'); exit; } $dsn = 'mysql:dbname=mydatabase;host=localhost'; $dbUser='myuser'; $dbPassword= 'password'; try{ $connection = new PDO($dsn, $dbUser, $dbPassword); } catch (PDOException $exception){ $_SESSION['messages'][] = 'Connection failed: ' . $exception->getMessage(); header('Location: register.php'); exit; }
messages.php <?php session_start(); if (empty($_SESSION['messages'])){ return; } $messages = $_SESSION['messages']; unset($_SESSION['messages']); ?> <ul> <?php foreach ($messages as $message): ?> <li><?php echo $message; ?></li> <?php endforeach; ?> </ul> Edited Wednesday at 12:49 AM by bee65 As the title above says im trying to use this code: Code: [Select] require_once("http://www.example.com/connect_file.php"); its giving this error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'username'@'localhost' (using password: NO) in /template/header.php on line 56 if i was to just use this code it works fine: Code: [Select] require_once("./connect_file.php"); Just incase it makes a difference, im testing this on index.php, however the codes above are not inside index.php, instead they are inside my /templates/header.php file which is included at the top of index.php any ideas? |