Forums / General Questions / Can't include catalog functions in seperate PHP file.

Can't include catalog functions in seperate PHP file.

Views: 4,017

Results 1 to 20 of 39
27 May 2011, 12:24 PM
#1
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Can't include catalog functions in seperate PHP file.

I have created a folder on root and with some php files in it.
Whenever i include the following line at the top of the php file:

require('../includes/functions/functions_general.php');

I get error that "failed to open this file.

Please note that path is correct, i have checked it 10 times.

What is the reason for that?

How can I resolve this issue?

27 May 2011, 2:27 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Can't include catalog functions in seperate PHP file.

Please explain in detail what it is you are trying to accomplish

Zen-Venom Get Bitten

27 May 2011, 7:07 PM
#3
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

I just want to call zen functions like storing data in database using $db->Execute plus some other functions for reading categories and sub categories name using zen cart functions.

I have created a new php file on root directory where zen cart is installed but I'm not able to access these functions in the php files created at root.

For example https://www.mydomain.com/myphpfile.php

In this file i want to call zen cart functions for accessing database and some other functions for categories manipulation.

The zen cart functions are at:

https://www.mydomain.com/includes/functions/....

Please let me know if this is clear now.

27 May 2011, 9:44 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Can't include catalog functions in seperate PHP file.

So, you're writing scripts to run completely outside of Zen Cart but you want to hijack Zen Cart code to do something from outside Zen Cart?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 May 2011, 7:07 AM
#5
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

No, in fact I'm using Ajax using Jquery. The files are placed at different folders because when I place my php files inside includes/functions directory i'm not able to access it through AJAX call therefore i placed my files in root directory.

When I place files in root directory i no longer can access zen cart functions.

I'm not doing any hijacking or cracking stuff just adding AJAX calls to my zencart.

28 May 2011, 12:21 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Can't include catalog functions in seperate PHP file.

Your script needs to load /includes/application_top.php ... which will in turn load everything else needed for Zen Cart operation, including the functions files.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 May 2011, 12:24 PM
#7
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Can't include catalog functions in seperate PHP file.

Can try this

require('includes/application_top.php'); 

Zen-Venom Get Bitten

28 May 2011, 1:10 PM
#8
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

When I include require('../includes/application_top.php') at the top of the file, the function used inside my php file 'json_encode() stops working.

Can you tell me the reason for this?

28 May 2011, 3:38 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Can't include catalog functions in seperate PHP file.

Why are you adding "../"?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 May 2011, 8:14 PM
#10
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

IF i don't add that I get the following error:

[28-May-2011 08:03:36] PHP Warning: require(/includes/application_top.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/serverpath/myinfo.php
on line 3
[28-May-2011 08:03:36] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required '/includes/application_top.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/serverpath/myinfo.php on line 3

28 May 2011, 8:26 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Can't include catalog functions in seperate PHP file.

Sounds like a puzzling folder structure.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 May 2011, 9:51 PM
#12
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Can't include catalog functions in seperate PHP file.

If you have your ZenCart in a folder - - say "shop"

Try this and adjust for the folder name where you do have ZenCart installed

require('shop/includes/application_top.php');

Zen-Venom Get Bitten

29 May 2011, 5:44 AM
#13
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Zen cart is installed at root and my new folder is also placed at the root.
I'm also confused why this error comes if i remove '../' before the folder path.
I'm trying to fix this error.

29 May 2011, 6:20 AM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Can't include catalog functions in seperate PHP file.

Okay, if your script is stuffed into another folder, then yes you'll need to use the "../" to get it to load.

As for why your json script breaks, that's impossible to know without having a complete copy of your script and knowing what exactly it's trying to do.
Maybe you should turn on PHP error reporting and see what errors are being encountered by your script?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 May 2011, 6:47 AM
#15
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Can you tell me how can I turn on PHP error reporting?

29 May 2011, 7:00 AM
#16
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Dr. Byte, i want to store new data into the database using $db->Execute function.

Is there any specific file i can include at the top to access this function?

29 May 2011, 7:12 AM
#17
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

PHP Code:

require('../admin/includes/functions/database.php');

if ($_POST['submit_personal']) {
	/* First Name validations Start */
	if (empty($_POST['firstname'])) {
		$message['status'] = false;
		$message['position'] = 'firstname';
	    $message['message'] = ' Enter first name...';	
	    echo json_encode($message);
	}
	else if (!preg_match("#^[-A-Za-z' ]*$#",$_POST['firstname'])) {
	  	$message['status'] = false;
		$message['position'] = 'firstname';
	   	$message['message'] = ' Not a valid first name...';
	   	echo json_encode($message);
	}
	/* First Name validations End */

	else {
	
		$query = "INSERT INTO my_table (expert_id, 
												 expert_firstname
												 ) 
	
		VALUES ('NULL', 
												 '".zen_db_prepare_input($_POST['firstname'])."'						 )" ;
			
	
		mysql_query($query);
		$_SESSION['expert_id'] = zen_db_insert_id();
		$message['status'] = true;
		$message['message'] = 'Your personal data is successfully added';
		echo json_encode($message);
	}
}

This code works fine but if i include require('../includes/application_top.php'); at the top the script stops working.

29 May 2011, 12:09 PM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Can't include catalog functions in seperate PHP file.

You can't re-load that database.php file if you've already loaded application_top. You'll need to remove that line.
And, if this is all intended to be admin-side, then you should be loading the admin application_top, not the storefront one.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 May 2011, 1:36 PM
#19
fawad123 avatar

fawad123

New Zenner

Join Date:
Oct 2009
Posts:
93
Plugin Contributions:
0

Re: Can't include catalog functions in seperate PHP file.

Dr. Byte i have found one problem when i include
require('../includes/application_top.php');

That AJAX stops working, whatever i send to JS file using echo command nothing appears on JS file.

I'm using JQUERY as shown:

success: function(response, status){
alert(response.length);
}

The length received is 0 but if i remove the application_top.php file i receive 167 bytes in response variable from PHP script.

Do you think there is any problem with application_top.php which hinders AJAX Call back?

P.S: I'm working on Store end not Admin end.

30 May 2011, 10:26 AM
#20
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Can't include catalog functions in seperate PHP file.

Using application top is appropriate and much safer than trying to include functions independently of their context.

However, to do so your admin ajax handler would need to be in your admin's root folder. From your path names, it looks as though you have it in a folder sitting alongside the place it needs to be.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)