I had a typical issue in my project where i had to pass request variables from one PHP to other with using FORM tag.
Example flow
- a.php gets parameters from client passes it to b.php
- b.php gets the params and had to pass those to c.php without people knowing.
It may seem easy but i had to scratch my hairs for a possible solution. (I am a begineer in PHP)
I thought about all of the possible solutions for solving this challenge and settled on this flow:
- User will submit the form, as usual from a.php.
- In the form processing b.php, I use CURL to execute a POST transmission to a c.php.
Code for b.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| $post=array('a'=>'b','c'=>'d');
foreach($post as $key=>$value) { $post_string .= $key.'='.$value.'&'; }
rtrim($post_string,'&');
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,'c.php');
curl_setopt($ch,CURLOPT_POST,count($post));
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch); |
This solution worked quite well so I thought I’d share it with you. Here’s how you execute a POST using the PHP CURL library.
Posted in PHP | Tagged CURL, HTTP POST, PHP |
Most of the people who are new to wamp do get this problem. I faced the similar problem. I setup wamp on my XP machine and everything ran fine.
I went into phpmyadmin and it gave me a warning that I should put a password up for mysql, otherwise people could just log right in, so I changed the password within phpmyadmin.
I opened D:\wamp\apps\phpmyadmin2.11.6\config.inc.php file and changed the password in config.inc.php by modifying $cfg['Servers'][$i]['password'] = ”; line to $cfg['Servers'][$i]['password'] = ‘devang’;
When i opened phpMyAdmin again it threw an error as
“MySQL said:
#1045 - Access denied for user ‘root’@'localhost’ (using password: NO)”
I scratched my head and did some googling. I found out a solution to this problem.
My mistake was that i changed the password in config.inc.php but i didn’t changed it for mysql.
So I went to “D:\wamp\apps\mysql\bin” and executed the following command at cmd prompt.
D:\wamp\apps\mysql\bin> mysql -u root
It gave me mysql prompt.
At mysql prompt i executed
mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’devang’);
Then i restarted all wamp services and opened phpMyAdmin and to my surprise it opened.
I had successfully changed the root password.
To summarize the steps
- Open config.inc.php from Wamp installation and change set the password in the line $cfg['Servers'][$i]['password'] = ”;
- Change MYSQL password for root by going to mysql\bin directory and execute “mysql -u root” at cmd prompt. This will give you mysql prompt.
- At mysql prompt execute SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’desired_password’);
- Restart all wamp services and you are done.
Posted in PHP | Tagged WAMP PHP 1045 |