note 129307 added to function.session-start
| From: | Anonymous | Date: | Mon, 04 Mar 2024 11:18:37 +0000 |
| Subject: | note 129307 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221231@lists.php.net to get a copy of this message | ||
Un ejemplo de sesion, comprobamos si los datos introducidos son validos:
<?php
session_start();
$conexion=mysqli_connect('localhost', 'root', '', 'examen');
#ComprobarUser
if(isset($_POST["email"]) && isset($_POST["password"])){
$email=$_POST["email"];
$password = $_POST["password"];
$sql="SELECT * from usuarios where email = '$email' and password =
'$password' ";
$result=mysqli_query($conexion,$sql);
if(mysqli_num_rows($result)>0){
while($datos = mysqli_fetch_assoc($result)){
$_SESSION["user"]=$datos["email"];
}
header("Location: muestraProductos.php");
}
else{
header("Location: prueba.php");
}
}
else{
header("Location: prueba.php");
}
?>
Y aqui comprobamos en el carrito los productos correspondientes a ese usuario:
<?php
#Carrito
session_start();
if(isset($_SESSION["carrito"])){
?>
<table >
<tr>
<th>CategorÃa</th>
<th>Color</th>
<th>Marca</th>
<th>Precio</th>
</tr>
<?php
$total=0;
foreach($_SESSION["carrito"] as $indice => $valor){
echo "<tr>";
echo "<td>".$valor["categoria"]."</td>";
echo "<td>".$valor["color"]."</td>";
echo "<td>".$valor["marca"]."</td>";
echo "<td>".$valor["precio"]."â¬</td>";
echo "</tr>";
$total = $total+$valor["precio"];
}
echo $total."⬠";
echo "<a href='pagar.php'><button
type='button'>Pagar</button></a>";
}
else{
echo "<h1>El carrito está vacÃo</h1>";
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 195.53.92.167)
----
Manual Page -- https://php.net/manual/en/function.session-start.php
Edit -- https://main.php.net/note/edit/129307
Del: integrated -- https://main.php.net/note/delete/129307/integrated
Del: useless -- https://main.php.net/note/delete/129307/useless
Del: bad code -- https://main.php.net/note/delete/129307/bad+code
Del: spam -- https://main.php.net/note/delete/129307/spam
Del: non-english -- https://main.php.net/note/delete/129307/non-english
Del: in docs -- https://main.php.net/note/delete/129307/in+docs
Del: other reasons-- https://main.php.net/note/delete/129307
Reject -- https://main.php.net/note/reject/129307
Search -- https://main.php.net/manage/user-notes.php