Cookie<

liunx

Guest
Hi all.

I'm new in php scripting, so I would aprecheate some help with cookies.

I've serched several forms and didn't understood nothing about it.
Some will say that I'm dumb.

Here is my problem.

I've got form that is checking that email and password are corect, and it they are take ID value of user.

How can I put user ID value in cookie, and later when needed read that value from it?

Here is code.


<?php

include("con_db.php");

mysql_select_db("iznajmljivaci") or
die("Nije moguće pristupiti bazi podataka");

/* provjera dali ulaz postoji */

$sel = "SELECT * FROM iznajmljivaci where email = '$email' and lozinka = '$lozinka'";
$quer = mysql_query($sel);
$row = mysql_fetch_array($quer);
$final = $row["redni_broj"];

$broj = $row["redni_broj"];
$Ime = $row["yourname"];
$Prezime = $row["Last_name"];
$email = $row["email"];


if ($final == "") {

echo "<br>\n";
echo "Do姝璷 je do gre姝琫 u registraciji korisnika.";
echo "<br>\n";
echo "<br>\n";
echo "E-mail, $email ne postoji u bazi podataka, ili je pogre姝痮 upisan. ";
echo "<br>\n";
echo "<br>\n";
echo "Lozinka koju ste upisali ne nalazi se u bazi podataka, ili je pogre姝痮 upisana.";
echo "<br>\n";
echo "<br>\n";
echo "<br>\n";
print "Molim probajte <a href='http://www.htmlforums.com/archive/index.php/prijava_korisn.php'>ponovo</a>, ili se <a href='http://www.htmlforums.com/archive/index.php/forma_za_unos_u_tablicu_iznajmljivaca.php'>registrirajte</a>.";
echo "<br>\n";
echo "<br>\n";


} else {



echo 'Dobrodo姝璱 ';
echo $Ime;
echo ' ';
echo $Prezime;
echo '!';
echo "<br>\n";
echo "<br>\n";
echo 'Ovdje mo鐎峵e dodati nove smje姝礱jne kapacitete: ';
print "<a href='http://www.htmlforums.com/archive/index.php/frm_unos_apartmani.php'>Apartman</a>, <a href='http://www.htmlforums.com/archive/index.php/nova_soba.php'>Soba</a>, <a href='http://www.htmlforums.com/archive/index.php/novi_agrotur.php'>Agroturizam</a>";
echo "<br>\n";
echo "<br>\n";
echo 'Ili urediti dosada姝痡e: ';
echo "<br>\n";
echo "<br>\n";

// NOW HERE I WANNA PUT COMMAND LINE TO SET COOKIE WITH ID VALUE = ($broj)

}

?>

Thank you

Coockie doesn't need do be set long life. When user close window cookie should be deleteddon't use cookies. they don't get deleted when the browers closes.

what you want to use is sessions.

$broj = $_SESSION['broj'] = $row["redni_broj"];

that will create a session and sessions will be deleted when the browser clsoes. now you have to have session_start(); on every page you want to use this variable on. so you need to add it at the very top


<?php
session_start();
include("con_db.php");

mysql_select_db("iznajmljivaci") or
die("Nije moguće pristupiti bazi podataka");

make sense?It makes sense

How do I transfer thi value now to another page, infact if I wanna wite that value what would command line be?

<?php
session_start();
echo broj;
?>

or

<?php
session_start();
echo $broj;
?><?php
session_start();
echo $_SESSION['broj'];
?>Now I get error:

Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\cro1\validacija.php:4) in c:\program files\apache group\apache\htdocs\cro1\validacija.php on line 120

Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\cro1\validacija.php:4) in c:\program files\apache group\apache\htdocs\cro1\validacija.php on line 120

Warning: open(/tmp\sess_3cfd0e8fcd7e401ebe571b20ebb5900f, O_RDWR) failed: No such file or directory (2) in c:\program files\apache group\apache\htdocs\cro1\validacija.php on line 120

Line 120 is:

<?php
session_start(); //LINE 120

include("con_db.php");

mysql_select_db("iznajmljivaci") or
die("Nije moguće pristupiti bazi podataka");

/* provjera dali ulaz postoji */

$sel = "SELECT * FROM iznajmljivaci where email = '$email' and lozinka = '$lozinka'";
$quer = mysql_query($sel);
$row = mysql_fetch_array($quer);
$final = $row["redni_broj"];


$broj = $_SESSION['broj'] = $row["redni_broj"];

//$broj = $row["redni_broj"];
$Ime = $row["yourname"];
$Prezime = $row["Last_name"];

etc......

Pehaps because I'm using template?session_start(); //LINE 120

that HAS to be line 2 or the first line after <?php at the very top of the document.it is not working


how can i make variable "$broj" global, and if it is global, could i print that variable on any page in any moment?
 
Back
Top