/    Sign up×
Community /Pin to ProfileBookmark

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šlo je do greške u registraciji korisnika.”;
echo “<br>n”;
echo “<br>n”;
echo “E-mail, $email ne postoji u bazi podataka, ili je pogrešno upisan. “;
echo “<br>n”;
echo “<br>n”;
echo “Lozinka koju ste upisali ne nalazi se u bazi podataka, ili je pogrešno upisana.”;
echo “<br>n”;
echo “<br>n”;
echo “<br>n”;
print “Molim probajte <a href=’prijava_korisn.php’>ponovo</a>, ili se <a href=’forma_za_unos_u_tablicu_iznajmljivaca.php’>registrirajte</a>.”;
echo “<br>n”;
echo “<br>n”;

} else {

echo ‘Dobrodošli ‘;
echo $Ime;
echo ‘ ‘;
echo $Prezime;
echo ‘!’;
echo “<br>n”;
echo “<br>n”;
echo ‘Ovdje možete dodati nove smještajne kapacitete: ‘;
print “<a href=’frm_unos_apartmani.php’>Apartman</a>, <a href=’nova_soba.php’>Soba</a>, <a href=’novi_agrotur.php’>Agroturizam</a>”;
echo “<br>n”;
echo “<br>n”;
echo ‘Ili urediti dosadašnje: ‘;
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 deleted

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@pyroApr 29.2004 — Try something like this, where $id is the variable that the users ID is stored in.

[code=php]setcookie("cookiename", $id);[/code]
×

Success!

Help @ddragas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...