Latest PHP Questions

Google Search

Loading
Do you want to write any post/blog so that people can read it, share it , comment it.
Click here to write a post

 
Php questions and answers user photo
 

What is the difference between a session variable and cookie?


Asked by:   Websiteforbusinessca On   Monday 29th of July 2013 06:34:55 AM

Total Answers:   1
 
Best Answer
 
Php questions and answers user photo
 

A cookie is a file that is saved on a local machine. As such, anyone on that machine has access to the data in your cookie. JavaScript can also access the cookie information (there are some restrictions). A user can always look inside of their cookie data and see what a website is saving. This is useful when you want to persist data, especially when that data needs to be used in PHP and in JavaScript, but since it's accessible through the client, you should never save any private information in there.

That's where Session comes in. The way that sessions work is that each user is assigned an ID, which is actually stored in a cookie. That ID is a key to the actual data, but that data is stored on the server. Since that data is stored on the server, only PHP/server has access to it and therefore it's secure to use for persisting personal user information.

The main disadvantage of Sessions is that your server requires more resources to store that data. As such, you can't save something in Session for ever. On top of that, JavaScript and any other client-side applications will not have access to that data. The rule is that you should persist data in cookies for everything besides private/personal user information.



Answered by:   Masked On   Thursday 22nd of August 2013 11:18:32 PM
Total star: star2 star2 star2 star2 star2
Rate this star1 stat1 star1 star1 star1

Php questions and answers user photo
 

Sorry I'm kind of new to this site so I'm not exactly sure how this works. I have a php character encoding problem. Basically my program needs to take in characters, some of which are special characters and display their values. Here is a simplified version of the part which doesn't work:

$string = "français";
for ($i = 0; $i < strlen($string); $i++)
{
echo ord($string[$i]) . " ";
}

The problem comes about when it tries to echo ord($string[$i]) when i equals 4 at which point it must echo ord(ç) which doesn't work for some reason. What could I do instead so that it gives me the right value for ç and other special characters?


Asked by:   George28 On   Monday 8th of July 2013 10:19:13 AM

Total Answers:   0
Php questions and answers user photo
 

Anyone can help me... I want to search by name or agreementNum but it doesnt work, it only search by name

<?php
$con = mysql_connect("localhost","root","negar");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("aruba", $con);

$a1=$_POST['u_Name'];
$a2=$_POST['u_Agreement'];


$sql=" SELECT * FROM customer
WHERE Name like ('%$a1%')
OR AgreementNum ='$a2'


";




$q=mysql_query($sql);
$x=mysql_fetch_array($q);

?>

i tried to use if but again doesnt work :( im beginner

<?php
$con = mysql_connect("localhost","root","negar");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("aruba", $con);

$a1=$_POST['u_Name'];
$a2=$_POST['u_Agreement'];


if ($a2=""){
$sql=" SELECT * FROM customer
WHERE Name like ('%$a1%') ";
}
if ($a1=""){
$sql=" SELECT * FROM customer
WHERE AgreementNum like ('%$a2%') ";
}



$q=mysql_query($sql);
$x=mysql_fetch_array($q);

?><table>
<tr><td><b>Customer Name:</b></td><td><?php echo" " ,$x['Name'];
?></td><?php
?><tr><td><b>Address:</b></td><td><?php echo"", $x['Address'];
?></td><?php
?><tr><td><b>Contact Person:</b></td><td><?php echo" " ,$x['Sales'];
?></td><?php
?><tr><td><b>Phone Number: </b></td><td><?php echo" ", $x['PhoneNum'];
?></td><?php
?><tr><td><b>Maintenance Agreement No:</b></td><td><?php echo" " ,$x['AgreementNum'];
?></td><?php
?><tr><td><b>Start Date:</b></td><td><?php echo" " ,$x['StartDate'];
?></td><?php
?><tr><td><b>End Date: :</b></td><td><?php echo" " ,$x['EndDate'];
?></td><?php
?><tr><td><b>Reseller Name:</b></td><td><?php echo" " ,$x['Reseller'];
?></td><?php
?><tr><td><b>Product Model:</b></td><td><?php echo" " ,$x['ModelNum'];
?></td><?php
?><tr><td><b>Remarks:</b></td><td><?php echo" " ,$x['Quantity'];
?></td><?php
mysql_close($con)
?>


Asked by:   N_peymanfar On   Monday 3rd of June 2013 08:43:43 AM

Total Answers:   1
 
Best Answer
 
Php questions and answers user photo
 

Use it like this

WHERE Name LIKE ('%$a1%')

use LIKE instead of like



Answered by:   Je_1310 On   Tuesday 2nd of July 2013 02:53:22 AM
Total star: star2 star2 star2
Rate this star1 stat1 star1 star1 star1

Php questions and answers user photo
 

0 down vote favorite


I wana to assign a variable such as 'heloo' to an address such as ->system_settings->settings->hostname and i write a function for.now when i write that address manually this function work correctly and assign 'hello' to that address,but,when i wana to gave address dynamically it doesn't work. my function :

<?php
write_xml("->system_settings->settings->hostname",'Helloooooooo');
function write_xml($tag_address,$value) {

$xml = simplexml_load_file("test.xml")
or die("Error: Cannot create object");
// $xml->system_settings->settings->hostname = $value;
$xml->$tag_address=$value;
$xml->asXML("test.xml");

}
?>

when i run the command line it works but in dynamical mode it doesn't work and identifies $tag_address in this line $xml->$tag_address=$value; as a string,not as an address. what should i do? TNX


Asked by:   Sepideh On   Monday 27th of May 2013 10:36:09 AM

Total Answers:   1
 
Best Answer
 
Php questions and answers user photo
 

Let me know if this helps

$pathVariables = explode('->', $tag_address);
$innerVariable = $xml;
for ($i = 0, $length = count($pathVariables); $i < $length; $i++) {
if (!empty($pathVariables[$i])) {
$pathVariable = $pathVariables[$i];
if (property_exists($innerVariable, $pathVariable)) {
// If we are at the end
if ($i+1 === $length) {
$innerVariable->$pathVariable = $value;
} else {
$innerVariable = $innerVariable->$pathVariable;
}
} else {
break;
}
}
}



Answered by:   Masked On   Thursday 22nd of August 2013 11:50:49 PM
Total star: star2 star2 star2 star2 star2
Rate this star1 stat1 star1 star1 star1

Php questions and answers user photo
 

The following code :
<?php
$a=0;
if($a=0)
{
echo "true";
}
else
{
echo "false";
}
?>

Gives output false. Please reason it!


Asked by:   Aish.saxena84 On   Thursday 23rd of May 2013 12:58:55 PM

Total Answers:   1
 
Best Answer
 
Php questions and answers user photo
 

In IF conditions are specified for checking equality as follows

if($a==0)

the code you used in the program
if($a=0) is assigning the value to the statement rather to check and compare, and returning boolean value 0 to the if statment causes to skip the if statement to be followed.



Answered by:   Je_1310 On   Tuesday 2nd of July 2013 03:00:57 AM
Total star: star2 star2 star2 star2 star2
Rate this star1 stat1 star1 star1 star1

Php questions and answers user photo
 

Suppose I have this code

$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;



if(!exists) {

$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;
}


else {
$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;

}

Now I don't want those codes to copy paste repetitively, but instead I want to come up with a function - So I probably have to create a function in php then??


function list ()

{
$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;

}

$value = function list();

if (!exists)

{
$value

}


else {

$value

}

How does this work please?


Asked by:   Nochlux On   Wednesday 15th of May 2013 02:23:41 AM

Total Answers:   0
Php questions and answers user photo
 

I am trying to do a simple comment function, where you write your name and comment in different fields, press submit and than the comment appears.

In my PHP file, I have this :

<?php

$name = $_POST['name'];
$comment = $_POST['comment'];


<div><?php echo $name ?></div>
<div><?php echo $comment ?></div>


?>

When I upload it and press the submit button, it says:


Parse error: syntax error, unexpected '<' in (filename) on line 7

What am I supposed to change?

Thank you.


Asked by:   Web_student On   Friday 19th of April 2013 03:19:52 PM

Total Answers:   3
 
Best Answer
 
Php questions and answers user photo
 

You are mixing PHP and HTML. The parser thinks that the DIV is part of PHP, which is why you get that error.

You need to end php after you set your variables, like this:

$name = $_POST['name'];
$comment = $_POST['comment'];
?>








Answered by:   Masked On   Friday 23rd of August 2013 12:01:36 AM
Total star: star2 star2 star2 star2 star2
Rate this star1 stat1 star1 star1 star1

Php questions and answers user photo
 

How can i add mp4 file to folder?


Asked by:   Xaqan On   Saturday 16th of March 2013 05:58:40 PM

Total Answers:   0
Php questions and answers user photo
 

<?php
session_start();
if(isset($_SESSION['email']))
{
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("yaron") or die (mysql_error());
$email =$_SESSION['email'];

$result=mysql_query("SELECT * FROM users WHERE email = '$email'");
$row = mysql_fetch_array($result);
echo $row['fistname'];
echo $row['email'];
echo $row['password'];
header('Content-Type: image/jpeg');
$img = $row['image'];
readfile($img);
header('Content-Type: image/jpeg');
echo "<img src =$img>";
echo "<br/>";

}
else
{
header("Location:index.php");
}



?>





//hi frnd i am trying to display my image form mysql database and i am using this code but it is not working plz help me.....................



Asked by:   Tarun On   Thursday 24th of January 2013 08:34:59 AM

Total Answers:   0
Php questions and answers user photo
 

I designed some Info System. But the weakness it has is that "Much as i designed a login pg and a logout pg 4 it, One can access any of it's pgs as long as you can type in the URL "

So i have been trying to incorporate in Some Session fns but my compiler has refused to run them. Much as i've written them at the top before any other Line code, it continuously displayed this error: "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\Sem\Practicals\Functions.php:2) in C:\wamp\www\Sem\Practicals\Functions.php on line 7"

Similarly it doesn't run the "header function"

Please, How can i solve these problems: 1. System security. 2. Stop the warnings about those functions (I'm using php5). thnx


Asked by:   Bobic On   Monday 21st of January 2013 02:54:31 PM

Total Answers:   1
 
Best Answer
 
Php questions and answers user photo
 

First write your code here..



Answered by:   Sumi On   Wednesday 23rd of January 2013 05:00:44 AM
Total star: star2 star2
Rate this star1 stat1 star1 star1 star1

  • Chat with me  Chat with Me
    Do you have any question of which you didn't find the answer yet ?

    ....... Go To Top

    Dedicated to all those who love PHP...