I've got a PHP application and I'm having trouble getting a User object from the SESSION.
When saving the object I have the following code (some other file).
$_SESSION['user'] = serialize($user);
The problem begins when I try and load a file called timeline.php. The first time I load the page (after I've logged in and the SESSION['user] is set) the page works fine. When I refresh the page I get an error 500.
The error log shows this:
Call to a member function get() on a non-object in timeline.php on line 10.
The code from line 2-10 is this:
include_once('isUserLoggedIn.php');
require_once('classes/User.php');
session_start();
$user = unserialize($_SESSION['user']);
require_once('classes/Database.php');
$tweets = Database::getTimeline($user->get('user_id'));
Can anyone offer any reason for this?
UPDATE (1)
In timeline.php I added var_dump($user) to line 8. The first time I load the page it gives me the correct value.
The second time I load the page it gives me bool(false).
UPDATE (2)
The problem seems to be with the host (perhaps a setting in the php.ini file there). The company I was using is Fatcow. When I used someone elses host (1and1) the issue didn't happen.
When unserializing objects lots of strange things can occur, see the PHP manual page for more information.
http://php.net/manual/en/function.unserialize.php
This comment seems pertinent:
http://www.php.net/manual/en/function.unserialize.php#77826
Related
The one page checkout for my store doesn't complete. On the final step (order review), I get this error as a return from the Ajax call to checkout/onepage/saveOrder:
Server was unable to read request. ---> There is an error in the XML document. ---> Input string was not in a correct format.{"success":true,"error":false}
After logging every variable and array I could find in the saveOrderAction method of OnepageController.php, it looks like the redirectUrl from this line is returning nothing:
$redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
I haven't found anyone else having this exact problem, and I have a feeling this is being caused by some admin setting that I missed while setting my store up. The production site works fine and I've copied every file onto my local server. Any ideas?
I set the permissions so that anonymous users can see xhprof but I can't seem to see the link at the bottom of the page when the page loads. I am able to view the page /admin/reports/xhprof/ as anonymous but just can't get the link to appear. I am sure it isn't hidden because I can't find it in Firebug.
I tried flushing the cache and running cron but still no luck.
I added a print_r to the following part of the xhprof code and I get some weird character response. So it leads me to believe that it is a problem somewhere with drupal_register_shutdown_function.
function xhprof_boot() {
// Initialize XHProf.
if (xhprof_xhprof_enable()) {
print_r(drupal_register_shutdown_function('xhprof_shutdown'));
}
}
I get a response of weird characters:
Array ( [0] => Array ( [callback] => xhprof_shutdown [arguments] => Array ( ) ) )
����r�H�0xmE�;T��mI� <��d�=�N�[��d�n�F(��##It��{���#���ͣ̓lfU�D$(QRwR�%�CfVVVfVV֫����?�쐞
�7�ɻ��[$� ��Ba�|�|xs~x����]JJ�b��s�#��������u�����n�:��l�Q���G�P���<-�
.....
.....
Fatal error: Call to undefined function drupal_get_path_alias() in
.../includes/common.inc on line 2250
Weird thing is I do have an older database of my site and the problem doesn't happen. Only happens on my production database copy of my site.
I tried commenting out every function that calls drupal_register_shutdown_function or register_shutdown_function but I can't seem to find what is causing the problem on my site.
I was able to fix my issue by going to Configuration -> Development and unchecking "Compress cached pages". This way I able to clear the cache and view the page as anonymous and see the link.
If I try to view the page the second time (since it is cached). I get this error below: Fatal error: Call to undefined function url() in .../sites/all/modules/xhprof/xhprof.module on line 190. I think that the xhprof was just meant to be viewed on on uncached pages.
I'm very new to the idea of adding values to a database, so would like some advise on whether this is possible and how I would do it.
I have a code that counts the lines of code written in a project, the code has to be in the folder that it is counting the lines of code from however I want to display this number on my site elsewhere. My site is a wordpress one, so i thought of sending this number to the database and calling on it in a template file elsewhere.
Is there a way to send this number to my database and have it keep up to date in real-time so that I can call it from other places in my site?
My LOC script can be seen running here:
http://www.skizzar.com/wp-content/loc.php
and the number is displayed using the command:
$folder -> count_lines()
update
I've added the following code to my loc.php
$num_of_lines = $folder -> count_lines();
add_option('line_count', $num_of_lines);
And called it in my theme files using
echo get_option('line_count', '0');
So far this just returns 0 as the value and causes a fatal error on loc.php "call to undefined function..."
Second update
Got the code to work by adding
require_once('wp-config.php');
To the top of my code, the issue now is that it doesn't update in real time - is there a way to do this?
Assuming you are saving the value to the database with wordpress as well, use add_option and get_option. Something like this:
add_option('line_count', $num_of_lines);
And in your template, display it with:
echo get_option('line_count', '0');
I am having an issue with a site that I am moving onto a new server. This site is connected to a SQL Server database, and is working correctly in it's current location. However, the new location is having problems with a single mssql_execute. Here is a sample of the code:
function get_customer_select_info() {
$link = get_db_link();
$customer_all_command_text = "dbo.Customer_All";
$customer_all_stmt = mssql_init($customer_all_command_text, $link);
$search = "%";
mssql_bind($customer_all_stmt, "#parm1", $search, SQLVARCHAR, false, false, 15);
$result = mssql_execute($customer_all_stmt);
mssql_free_statement($customer_all_stmt);
return $result;
}
Calling the above function results in
Unable to load the webpage because the server sent no data.
Error code: ERR_EMPTY_RESPONSE
from Chrome.
get_db_link retrieves a new connection to the database, or returns the current one if it already exists. It is functioning correctly. I have tried just closing the link and creating a new one if one already exists, which had no effect on the error.
This is not a problem connecting to the database because before this stored procedure is executed, three others are called and executed correctly.
Another complication is that running a trace on the given database results in this stored procedure getting called on the database and being successful!
Commenting out the mssql_execute makes the page load correctly (minus the information that this function returns).
Again, the same exact code on the current server works correctly, but the code on the new server is causing problems. I can't obtain any debugging information from apache or php because it is not actually sending anything.
If you facing ERR_EMPTY_RESPONSE then i will suggest you to follow these steps
Refresh page and restart browser
Clean your cache and browser cookies
Check internet connection
Update Google Chrome
Check router
I am also sharing video tutorial where you will find the complete solution of given steps to resolve your problem here is the link
http://vimeo.com/60824619
Best of luck
If someone doesn't feel like reading the whole explanation, you can skip to the last 2 paragraphs where I have the actual question
So I have this bunch of websites made with CakePHP. In one of the pages (this is the same for all the websites), I load an XML file and process its contents (using the XML helper). This has been working for quite some time. Now, suddenly, it doesn't work anymore in any of the websites (and the code hasn't changed a bit), it gives an "error opening file".
At the same time, another script of those websites (which has nothing to do with the previous one, it's plain PHP, outside the cakephp "area") has stopped working too. In this case, it's a scripts that creates a connection with a video hosting provider (Fliqz) and retrieves the URL of a video given a video id. Suddently, it throws an error something like "session was not created" (the script creates some sort of session with Fliqz' server to get the URL).
All this sounds very weird, I know. The first thing I've done, after checking that the code is correct, is call 1&1 (the hosting provider) and ask if they have made any change in the server. They said that they changed to PHP5 a few months ago (which I was aware of, and everything was working fine after that change), but that they haven't changed anything else.
My question would be, is there anything I can do to figure out what is causing these problems? For example, I found some post of someone saying that his hosting had restricted some functionality that allowed external connections. Or in another post I saw a suggestion about doing this: echo file_get_contents("http://google.com/") and I got an error, meaning that some setting wasn't right. I even tried to use simplexml_load_file (instead of the XMl helper) in the page where I load the XML file and didn't work, giving another error...
I would like to know, if a PHP setting is causing this, which one could it be, so I can look at it and call again 1&1 to tell them what they need to change (if there's anything to change). Otherwise, how in the world can something just stop working?
Thank you for any advice! It is much appreciated!
EDIT: detailed explanation of errors
1. Error related to the XML not loading using CakePHP's XML helper
This is the code I use (which used to worked perfectly):
$completeurl = '/full/path/to/file/myfile.xml';
App::import('Xml');
$xml =& new XML($completeurl);
$this->list = Set::reverse($xml);
I don't get any error or warning. If I debug $xml, I get this:
Xml Object
(
[__parser] =>
[__file] =>
[__rawData] =>
[__header] =>
[__tags] => Array
(
)
[version] => 1.0
[encoding] => UTF-8
[name] => #document
[namespace] =>
[namespaces] => Array
(
)
[value] =>
[attributes] => Array
(
)
[children] => Array
(
)
[__parent] =>
)
If I debug $this->list I get an empty array. Before this problem, I would get an associative array with all the information of the XML file, perfectly structured. Oh, and the XML file is the same it used to be, and I've revalidated it just in case giving no errors.
2. Error related to XML file not loading using simplexml_load_file()
This is the code I've tried with "regular" php (without using any CakePHP helper):
$file = '/full/path/to/file/myfile.xml';
if(!$xml = simplexml_load_file($file))
exit('Failed to open '.$file);
And this are the errors (warnings):
Warning (2): simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration [APP/plugins/icd_discovery/webroot/videos.php, line 29]
Warning (2): simplexml_load_file(http://discovery.ingles100.com/icd_discovery/xml/videos_unidades.xml) [function.simplexml-load-file]: failed to open stream: no suitable wrapper could be found [APP/plugins/icd_discovery/webroot/videos.php, line 29]
Warning (2): simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://discovery.ingles100.com/icd_discovery/xml/videos_unidades.xml" [APP/plugins/icd_discovery/webroot/videos.php, line 29]
If I put a relative path for the file, I just get the last warning, but still not loading it.
** 3. Error related to script to load URL of hosted videos in Fliqz**
The page that contains this script is totally unrelated to the previous ones (meaning that the code there doesn't affect the code here). We use the following script (provided by Fliqz) to request the URL of our videos hosted there:
include_once '../fliqz/dlMetrics.php';
// initializing new session
$videoID = '123123123';
$applicationID = '456456456';
$uniqueID = null;
// create a new fliqzDownload Object
$metricsObj = new dlMetrics();
// get new session, using Application ID from Account:
$sessionID = $metricsObj->newSession($applicationID,NULL,NULL,NULL,$uniqueID);
// show server time when new session was created:
$start = $metricsObj->getSessionStart();
// Get asset location (note: must use dashes in asset ID example: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
$video_URL = $metricsObj->initLoad($videoID);
By doing this, we would get the URL of the video in the $video_URL variable. Again, this used to work perfectly. Suddenly, it doesn't.
So is it a coincidence that all this things stop working? I think that something has changed somewhere. Not the code, I'm the only one who touches that. The PHP version changed a while ago, and everything was working fine. Something in the server? 1&1 says that they didn't, or at least the person I talked to. If I have to call back, I would like to be able to point a little better where do I think the problem might be coming from, that's why I need you help guys!
Again, thanks for any advice!
Create a file called php.ini with the following content:
allow_url_fopen = ON
and place it in the same folder (or folders) as those scripts.