PHP code not working on ipage hosting? - hosting

My code is working well on localhost and also on godaddy server.But on ipage I am getting "500 Internal Server error" with this code.
My local server has PHP Version 5.4.7 and my ipage hosting has PHP Version 5.3.13
public function cms($cid,$vars) {
global $db;
//fetch cms data from database
$stmt = $db->prepare("SELECT * FROM cms");
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $row;
if ($cid == ""){
$stmt = $db->prepare("SELECT * FROM cms");
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $row;
}
else {
$stmt = $db->prepare("SELECT * FROM cms WHERE id=? ");
$stmt->execute(array($cid));
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($vars == "") {
return $row;
}
else {
$ret = [];
foreach ($vars as $var) {
$ret[] = [
$var => $row[0][$var]
];
}
return $ret;
}
}
}

I think its version problem and for that you need to ask your hosting provider(ipage) to make your php version same as your local version..
Also check out your .htaccess file too, cos. some time redirection can also give this types of error.

if anyone facing internal server (500) error in ipage, you can chat or call them, then they will upgrade your version to 7 or above.
you can check your php version using this code.
<?php
phpinfo();
?>

Related

How to optimaze looping , get data from another API with lumen

when i use guzzle to get data member on join to data content is so heavy, can samebody tell me how to fix it?
$getNewest=$this->Get(env('TestUrl').'listcast');
if (!empty($getNewest['DATA'])) {
foreach ($getNewest['DATA'] as $data)
{
$client = New CLient();
$reqGet = $client->get(env('MemberUrl').'user-token-member/'.$data['member_id']);
$resGet = json_decode($reqGet->getBody(),true);
$array['id']=$data['id'];
$array['title']=$data['title'];
$array['member_name'] =$resGet['DATA']['FIRSTNAME']." ".$resGet['DATA']['LASTNAME'];
$array['avatar'] = $resGet['DATA']['MEMBER_IMAGE'];
$array['desc'] = $data['desc'];
$newest[] = $array;
}
} else {
$newest = array();
}
I don't know exactly what is the reason for its low speed, but there are some modifications that you should apply on your code.
Don't use env() in your code. Instead define a config file for example connection.php in config folder and set your configs in it, because config file will be cached in your production server by laravel. You can cache config by running php artisan config:cache
For example config/connection.php
<?php
return [
'test_url'=>env('TestUrl'),
'member_url'=>env('MemberUrl'),
];
It is not required to make a new object of Client class in every iteration of foreach. You put it outside of the loop.
$getNewest=$this->Get(config('connection.test_url').'listcast');
if (!empty($getNewest['DATA'])) {
$client = New CLient();
foreach ($getNewest['DATA'] as $data){
$reqGet = $client->get(config('connection.member_url').'user-token-member/'.$data['member_id']);
$resGet = json_decode($reqGet->getBody(),true);
$array['id']=$data['id'];
$array['title']=$data['title'];
$array['member_name'] =$resGet['DATA']['FIRSTNAME']." ".$resGet['DATA']['LASTNAME'];
$array['avatar'] = $resGet['DATA']['MEMBER_IMAGE'];
$array['desc'] = $data['desc'];
$newest[] = $array;
}
} else {
$newest = array();
}

Error Exception: Indirect modification of overloaded property laravel

I'm making an API that store a new version of an application. Here is my code:
public function saveNewVersion() {
$artifact_url = Input::get('url');
$artifact_id = Input::get('id');
$artifact_name = Input::get('name');
$artifact_version = Input::get('version');
$urls = explode('/', $artifact_url);
//Exploding URL to dir
$app_dir = "";
for($i=5; $i<sizeof($urls); $i++)
$app_dir .= $urls[$i] . '/';
$app_dir .= $artifact_id;
//Checking if the artifact_id exists in the database
$app = Applications::where('app_dir', '=', $app_dir);
if (!$app->count()) {
//Save it as new application
$new_app = new Applications();
$new_app->application->name = $artifact_name;
$new_app->app_dir = $app_dir;
$new_app->save();
$app_id = Applications::where('app_dir', '=', $app_dir)->first()->id;
} else {
$app_id = $app->first()->id;
//Checking if the application name is not same as newrelic (Optional)
if ($app->first()->application_name != $artifact_name) {
$app = $app->first();
$app->application_name = $artifact_name;
$app->save();
}
}
//check if the last version exists in the database
$version = Versions::where('application_id', '=', $app_id)->orderBy('id', 'desc');
$lastVersion = $version->first()->version_number;
if ($lastVersion != $artifact_version) {
//check if the new version is exists before
$flag = 0;
$versions = Versions::where('application_id', '=', $app_id)->orderBy('id', 'desc')->get();
foreach ($versions as $item) {
if ($item->version_number == $artifact_version) {
$flag = 1;
break;
}
}
if (!$flag) {
$version = new Versions();
$version->application_id = $app_id;
$version->version_number = $artifact_version;
$version->save();
echo 'Application' . $app_id . 'has been updated to version ' . $artifact_version;
}
}
}
When I call the API using postman, the API runs successfully and stores the new version of the application. But when I'm using CURL. I got ErrorException: Indirect modification of overloaded property App\Applications::$application and it points to my $new_app->save() code.
Is there any problem with my code ? Or are there some parameters used in postman that make this error invisible ?
I may be wrong here but it looks like the issue is the issue is here:
$new_app->application->name = $artifact_name;
I think it should be:
$new_app->application_name = $artifact_name;
based on the other code.

Session not remember, and why the session created each time I load the page?

I start to work with my project using laravel 5. I realized that it work fine in my local directory with session after I login to my site, But I just know that I got problem when I hosted my project to server. After I login each time, the session could not remember and recreated each time I loan the page. That cause the problem to me.
Laravel Login
public function postLogin(){
$hit = 0;
if(Request::ajax()){
$pw = Request::input('pw');
if(!empty($pw)){
$admin_pass = AdminPassword::first(['admin_pass']);
$ip_address = Request::ip();
if(!empty($admin_pass) && trim($admin_pass->admin_pass) == trim($pw)){
if(Auth::attempt(['username' => Request::input('username'), 'password' => Request::input('password'),'status'=>1])){
try{
$user = Auth::user();
$user->last_login = date('Y-m-d H:i:s');
$user->login_ip = $ip_address;
$user->save();
$permissions = Auth::user()->permission;
if(!empty($permissions) && count($permissions) >0){
session(['ROLE_PERMISSION'=>$permissions]);
}
$failed = FailedLogin::whereRaw('ip_address = INET_ATON(\''.$ip_address.'\')')->first();
if(!empty($failed)){
$failed->delete();
}
}catch (\Exception $ex){}
$url = Request::session()->pull('url.intended', '/');
return ['url'=>$url,'msg'=>'Successfully.','status'=>true,'hit'=>$hit];
}else{
$hit = $this->updateFailedLogin($ip_address,Request::input('username'));
}
}else{
$hit = $this->updateFailedLogin($ip_address,Request::input('username'));
}
}
}else{
return redirect()->route('login');
}
return ['url'=>'','msg'=>'Try again.','status'=>false,'hit'=>$hit];
}
Please help me out. This is the final step of my project.
Thank you in advanced.
It's possible you have SESSION_DRIVER in your .env set to file - depending on your hosting environment, this could mean that your session isn't persisting due to each request being served from a different file server (common in cloud environments).
Try changing your SESSION_DRIVER to database.
Did you put the
session_start();
in all your pages?
If not it might be your problem, I d suggest you to add this in your index directly

one codeigniter application folder run two website with different domain

could i use one codeigniter framework directory to create multiple applications?
I have two website with one CodeIgniter application, i am used one DB for both of website, system folder, config, view, controller etc are also same.
main website is working fine, all links are working and another website only home page is working, rest of the links are not working, when i am open another link the error is occur: "Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid." version of codeigniter is 2.2.0, please help.
Thanks in advance
Try this:
ex:
- subdomain1.hostname.com
- subdomain2.hostname.com
then in my front index:
// Host address
$host = $_SERVER['HTTP_HOST'];
$SERVER_NAME = $_SERVER['SERVER_NAME'];
define('HOST', $SERVER_NAME);
// Extract eventual subdomain
$host3 = strrpos($host, '.');
$host2 = substr($host, 0, $host3);
$host1 = strrpos($host2, '.');
$subdomain = substr($host, 0, $host1);
if($host == 'localhost') {
define('HOST_TYPE', 'localhost');
define('SUBDOMAIN', FALSE);
} else {
if($subdomain !== 'www' && $subdomain !== '') {
define('HOST_TYPE', 'subdomain');
define('SUBDOMAIN', $subdomain);
} else {
define('HOST_TYPE', 'site');
define('SUBDOMAIN', FALSE);
}
}
in my config.php config:
switch (HOST_TYPE) {
case 'subdomain':
$config['base_url'] = 'http://'.SUBDOMAIN.'.hostname.com/';
break;
case 'localhost':
$config['base_url'] = 'http://localhost/devpage/';
break;
default:
//$config['base_url'] = 'http://mainpage.com/';
break;
}
in my database.php config:
...
$db['default']['hostname'] = 'localhost';
switch (HOST_TYPE) {
case 'subdomain':
$username;
$password;
$con=mysqli_connect("localhost","username_db","password_db","name_db");
$query = "SELECT * FROM subdomain_table WHERE subdomain_name = '".SUBDOMAIN."';" or die("Error in the consult.." . mysqli_error($con));
if ($result = mysqli_query($con, $query)) {
while($row = mysqli_fetch_array($result)) {
$username = $row["username"];
$password = $row["password"];
}
}else{
mysqli_close($con);
redirect('http://hostname.com'); //No sudomain found or error page
}
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
mysqli_close($con);
}else{
}
mysqli_close($con);
$db['default']['database'] = 'db_prefix'.SUBDOMAIN;
$db['default']['username'] = 'username_prefix'.$usuario;
$db['default']['password'] = $password;
break;
case 'localhost':
$db['default']['database'] = 'local_dev_db_name';
$db['default']['username'] = 'some_username';
$db['default']['password'] = 'some_password';
break;
default:
redirect('http://mainpage.com');
break;
}
$db['default']['dbdriver'] = 'mysql';
...
finally the constants.php config:
//this one resolve all your links!!!!!
switch (HOST_TYPE) {
case 'subdomain':
define('URL','http://'.SUBDOMAIN.'.hostname.com/');
break;
case 'localhost':
define('URL','http://localhost/devpage/');
break;
default:
define('URL','http://mainpage.com/');
break;
}
I hope you find it useful
I think the answer by #avenda goes someway but as you've mentioned there is only 1x DB then there is no need to play around with that code.
I think your simplest solution in your config file is simply:
$config['base_url'] = $_SERVER['HTTP_HOST'];
And then in your routes file:
if ($_SERVER['HTTP_HOST'] == 'x'){
$routes['default_controller'] = 'xController';
} elseif ($_SERVER['HTTP_HOST'] == 'y'){
$routes['default_controller'] = 'yController';
}
Haven't tested it but have a similar need coming up on a project so will have to implement something similar.

Check if a file exist on remote server and save th url path in a magento attribute

Hi im trying to check if a file exist on a remote server and then save the url path to the file in a attribute on the product in magento.
This is how far i have got . i use some code from another function i have that imports images to my magento store. But i have never tested to only get the url path .
<?php
ini_set('display_errors', 1);
require_once('app/Mage.php');
Mage::app();
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$url = "http://www.imonline.se/media42/trailers/199151abe/swinks/hkmedia/";
foreach($_productCollection as $product)
{
//if(file_exists($serverurl))
{
$thispro = Mage::getModel('catalog/product')->load($product->getId());
$attributeValue = $thispro->getFaktaId();
$imgupdate = $thispro->getImgupdate();
if($thispro->getFaktaId()=="" || $thispro->getImage()=="no_selection")
{
if($attributeValue != "")
{
copy($url.$attributeValue );
$im = $attributeValue.".mp4";
if(file_exists)
{
$product->setFilmUrl($url.$im);
$product->save();
}
}
}
}
}
?>
file_exists - Checks whether a file or directory exists
To Check if Remote File Exists using PHP
$url = $url.$im;
$exist = file_exists_remote($url);
if($exist) {
echo 'File Exists';
$product->setFileUrl($url.$im);
$product->save();
} else {
echo 'File not found';
}

Resources