Skip to main content

Posts

Downloading file is corrupted - header

I have be trying to figure out what is wrong but every time i download the image and try to open it, it says that the file is corrupt. $h is the path which is pulled from the database, the $h displays the image on the page successfully but I dont get why it wont download. Any ideas ?? header("Pragma: public"); // required header("Cache-Control: private",false); // required for certain browsers header('Content-Length: '. filesize("../".$h)); header('Content-Type: application/octet-stream'); header('Content-Disposition: inline; filename="'.md5($h).$ext.'"'); header('Content-Transfer-Encoding:binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); readfile("../".$h);

Calling a Class function without using $this->function_name() — PHP --

So I have this class: class A{ public function do_a(){ return 'a_done';}; public function do_b(){ return 'b_done';}; } So I require the php file and create an instance of the class: require_once("A_class.php"); $System = new A(); require_once("user_calls.php"); //here I import the user file with the function calls. user_calls.php contents: echo 'this was the result of '.$System->do_a(); echo 'this was the result of '.$System->do_b(); So, that does work, but I don't want the user to have to use $System->do_a(); , but only do_a(); . Any solutions? EDIT: I also want to limit the functions the user could call in the user_calls.php file, to basic native php functions and those in class A.

Amazon EC2 Linux RH cannt connect from php script to RDS MYSQL

I have an amazon EC2 instance (redhat linux ) and a RDS (mysql 5.5 ). After stop /start EC2 instance. EC2's ip was changed and cannt connect RDS anymore. I can successfully connect RDS instance from command line. However, it is unable to connect from php script and give me this warning. PHP Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on 'applicantdb.xr3x2xcale.eu-west-1.rds' (13) It is working fine from my localhost and I can connect to localhost. It is really annoying and if somebody knows the solution. Please help me and I do really appreciate it.

Can we capture the same browser closing event without using “onunload”

Actually using the window.close , we can control whether browser is closed or not, but it works only for pop-ups created by the browser. So, are there any ways to listen to the closing event of the browser without using onunload ? Because we don't want things to be executed when back , refresh or forward actions occur. Please also reply if you know specifics regarding Firefox. Thanks in advance!

php, ajax authentication on external domain

Suppose I have domain-a.com (A) and domain-b.com (B) I'd like to be able to share php sessions between the two domains unifying logins in a way that once the user is logged to A is automatically logged into B and vice versa. Now, the problem I'm facing is that even if I managed to have the browser talk via ajax to an external domain via the Access-Control-Allow-Origin header it won't set cookies (please don't tell me "you can't set/get cookies for another domain, this is not the problem") here's the flow: A sends credentials to B if credentials are OK -B answers with the SESSID made in order to be consistent with the user credentials (so that it can be generated both ways ie: login from A or login from B), this will be used later to share the session created on B -At the same time I'd like that B could write cookies for its domain, but so far I wasn't able. What I need here is very simple, once that the credentials from A are

Apostrophe issue when inserting into MySQL

I have a script where I submit some fields that get entered into a MySQL database when I submit it now it goes through successfully but never gets inserted into the database if one of the fields has an apostrophe. What can I modify to get this to work? if ($_POST) { $name = trim($_POST['your_name']); $email = trim($_POST['your_email']); $answers = $_POST['answers']; $i = 0; foreach ($answers as $a) { if (trim($a)) $i++; } if ($name && $email && $i >= 40) { $array = array(); $q = mysql_query("select * from fields"); while($f = mysql_fetch_array($q)) $array[$f['label']] = $answers[$f['ID']]; $array = serialize($array); $time = time(); $ip = $_SERVER['REMOTE_ADDR']; $token = md5($time); $result = mysql_query("insert into data (submit_name, submit_email, submit_data, submit_confirm, submit_time, submit_ip, submit_token) values ('$name',