Archive for the ‘PHP’ Category

Accessing network shared folder using PHP with XAMPP

October 18, 2012 1 comment

Hi All,
I am encountering an issue while accessing Network drive using PHP with XAMPP from last 15 days.
Basically I never used XAMPP(with Window) in network throughout my programming career, & hence the issue is pretty new & confusion for me.
My Scenario:
I have a PC & a Laptop in LAN.Both having Windows 7 OS.I have installed an application on PC as well as Laptop.All data inserted into application from PC and I want to sync with Laptop on daily/weekly basis.
I searched a lot on internet and came across different techniques,I implement them but problem is not yet solved. Just Hereby briefing you all-
When you run Apache as a service on your Windows computer, it chooses to run as the LocalSystem account by default (usually SYSTEM). The LocalSystem account has no network privileges, makes it impossible to access networked resources (such as a shared drive) in your Apache service.

1. First, you have to change the user the Apache service runs as.
Go to your Services panel (Start -> Run -> “services.msc”).(Or tou can right-click My Computer icon on desktop,and select Manage)
Find the Service labeled Apache, right-click, and hit Properties.
Choose the “Log On” tab.
You’ll see that Apache is set up to run as the Local System Account.
You’ll want to change this to the second option, “This account”, and then fill in the details of the User account you would like Apache to run under.
Some sites tell you to create a special Apache-based user account just for this occasion. It’s not a bad idea, but then you have to make sure it has all of the proper permissions that an Apache user would need, such as read/write to to htdocs and the .conf and .log files, and permissions to log on as a service, etc etc – as well as the permissions to access the network resource you’re trying to get to in the first place.(I hadn’t tried this)
In light of that process, I chose to just run it under my own account instead.

To configure how a service is started using the Windows interface:
To specify account, click This account, click Browse, and then specify a user account in the Select User dialog box. When you are finished, click OK.If you still have problem to find exact User,go to advance option & then use “Find Now” functionality provided.Configure How a Service Is Started

Hit “Apply” – it’ll pop up a box saying you need to restart Apache to take effect, but hold off on that for a moment.
This is the tricky part: you have to give the user (the one you’re running Apache as) permissions to act as part of the OS.
Go to the Local Security Policy panel (Start -> Run -> “secpol.msc”).
Under the navigation section in the left sidebar, choose Local Policies -> User Rights Assignments.
In the right-hand frame, double-click the item “Act as part of the operating system” to open up its properties.
Select “Add User or Group, Enter the appropriate user in the box provided, and hit “OK.”
At this point, you are technically complete – Apache can now do the same things to the network resource that your user can – read, write, execute, whatever.
However, in Auther’s case, he was trying to create an actual readable resource, so he edited my Apache config file to create an alias to my share.
Open up your Apache configuration file. For most people it’s httpd.conf in the conf subdirectory of your Apache install directory.
The other thing that is tricky and caught me up is that unlike Apache, the Windows UNCs config file requires backslashes slashes, not forward. Now you can restart your Apache service

On Oct 22,2012:
Hurry…Now I can access the network folder,I even successfully transferred the files to the shared folder.
Now my next challenges:
1. File transfer time is bit more.
2. Transfer the Db files
Will get back if I can find some success..:)


How to call a PHP Script from ASP.NET C# and View Its response?

March 7, 2011 17 comments

Hi guys,
I was wondering on net abt , how to call a PHP Script from ASP.NET C#, then found a simple solution.
Actually, Its nothing but calling any other ASP.NET C# file.
The script is as follow:
Basically I wanted to send User Id and Account ID and then process the table:

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("" + item.Value + "&accountid=" + item.Key + "&type=stock");

// Set the 'Timeout' property in Milliseconds.
myRequest.Timeout = 600000;//10 mintutes
myRequest.Method = "GET";
HttpWebResponse newStream = (HttpWebResponse)myRequest.GetResponse();

if ((newStream.ContentLength > 0))
System.IO.StreamReader str = new System.IO.StreamReader(newStream.GetResponseStream());
if (str != null) str.Close();

The small changes I did was, I multi threaded the process, as i was taking more time to execute the PHP page “ProcessTrans.php”;
In above example, Data has been sent in “GET”
If you want to Post Data to remote Web Page using HttpWebRequest :

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("" + item.Value + "&accountid=" + item.Key + "&type=stock");
request.Method = "POST";
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(request.GetRequestStream());
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();

It might not work if the site you’re trying to stream is protected by authentication. If it’s Windows/NTLM Authentication and your account has privileges on the site, try using:
request.Credentials = CredentialCache.DefaultCredentials;
after the create request.



Categories: C#, General, PHP

Session Funda in PHP

March 5, 2010 Leave a comment

Hey guys,
It took me some time to understand basics of Session in php.
If you create a logout.php to end user session, the right sequence is as follows


he difference between both session_unset and session_destroy is as follows:

session_unset just clears out the sesison for usage. The session is still on the users computer. Note that by using session_unset, the variable still exists.

Using session_unset in tandem with session_destroy however, is a much more effective means of actually clearing out data. As stated in the example above, this works very well, cross browser:


I noticed that in firefox, one could simply use sesison_unset and the session would be cleared. When trying this on IE, I was horrified to find out that the data was still there, so I had to use session destroy.
(Ref :

session_unset() is like doing a session_unregister() on all registered variables. They can still be re-registered by calling session_register() whereas after session_destroy, they cannot.

If you want to clear all sessions:
$_SESSION = array();

Categories: Bugs, PHP, tricks

Problem while Sending mail through PHP

March 5, 2010 1 comment

Today i faced one problem while sending mail to mail account residing on my server.
I went through the link and found the solution.

The tag at the end of mail() function :
ie. mail($sendto,$subject,$message,$headers,””);
works great.
This is a sendmail command line flag. You can use -f to set the sender (“envelope from”) address. The PHP mail() function takes five parameters, including two optional ones that follow the three required ones you’re probably used to.

Categories: Bugs, PHP

Virtual Hosts

January 6, 2010 1 comment

Hello Friends,

Today I implemented interesting concept called “Virtual Hosts”.
The Apache HTTP Server’s built in virtual hosting allows the server to provide different information based on which IP address, hostname, or port is being requested.
To activate name-based virtual hosting, uncomment the NameVirtualHost line by removing the hash mark (#) and replace the asterisk (*) with the IP address assigned to the machine.

Next, configure a virtual host by uncommenting and customizing the container.

On the line, change the asterisk (*) to the server’s IP address. Change the ServerName to a valid DNS name assigned to the machine, and configure the other directives as necessary.

To create a name-based virtual host, it is best to use the virtual host container provided in httpd.conf as an example.

The virtual host example read as follows:

#NameVirtualHost *:80
# ServerAdmin
# DocumentRoot /www/docs/
# ServerName
# ErrorLog logs/
# CustomLog logs/ common

Note :- The location of httpd.conf may vary as per server.
In my case, it was apache centos.
To activate name-based virtual hosting, uncomment the NameVirtualHost line by removing the hash mark (#) and replace the asterisk (*) with the IP address assigned to the machine.

Next, configure a virtual host by uncommenting and customizing the container.

On the line, change the asterisk (*) to the server’s IP address. Change the ServerName to a valid DNS name assigned to the machine, and configure the other directives as necessary.

To activate a newly created virtual host, the Apache HTTP Server must be reloaded or restarted.


DocumentRoot /home/preetul

sudo /etc/init.d/httpd restart

Ref :

Categories: PHP, tricks

Increase PHP memory limit

December 9, 2009 Leave a comment


I got error Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 13050 bytes) in my file /home/developer/Sachin/API/performance.php on line 227
You can view memory limit using

1. If your memory is set to 8M, continue with next step
2. Open your php.ini file. If your server is a Webune Dedicated Server with Redhat, Centos or Fedora, you can run the following command to edit the php.ini file:
3. VIM /etc/php.ini (you can view its location in phpinfo())
4. Code:
memory_limit = 64M ; Maximum amount of memory a script may consume (6MB)
5. Save the changes.
6. Restart Apache Server with the following command
/etc/init.d/httpd restart
7. Done

Youcan set the memory limit within a file using ini_set() function:
at ini_set(‘memory_limit’, ’64m’); in your php page.

Categories: Bugs, mysql, PHP

MySQL Query Optimization – Indexing

September 30, 2009 Leave a comment

Indexing is the most important tool you have for speeding up queries. Other techniques are available to you, too, but generally the one thing that makes the most difference is the proper use of indexes.

MySQL uses indexes in several ways:

* As just described, indexes are used to speed up searches for rows matching terms of a WHERE clause or rows that match rows in other tables when performing joins.
* For queries that use the MIN() or MAX() functions, the smallest or largest value in an indexed column can be found quickly without examining every row.
* MySQL can often use indexes to perform sorting and grouping operations quickly for ORDER BY and GROUP BY clauses.
* Sometimes MySQL can use an index to reading all the information required for a query. Suppose that you’re selecting values from an indexed numeric column in a MyISAM table, and you’re not selecting other columns from the table. In this case, when MySQL reads an index value from the index file, it obtains the same value that it would get by reading the data file. There’s no reason to read values twice, so the data file need not even be consulted.


Categories: database, mysql, PHP, SQL