Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

<?

php

//whether ip is
from the share internet
if(!
empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip =
$_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from
the proxy
elseif (!
empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip =
$_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is
from the remote address
else{
$ip =
$_SERVER['REMOTE_ADDR'];
}

//$ip
= getIPAddress();
echo 'User Real IP
Address - '.$ip;

if(isset($_GET['add_to_cart'])){

$get_article_id=$_GET['add_to_cart'];

$select_query="SELECT * FROM detailpanier WHERE ip_adress=$ip and


id_article=$get_article_id";

$result_query=mysqli_query($dbhandle,$select_query);

$num_of_rows=mysqli_num_rows($result_query);
if($num_of_rows>0)
{
/*echo
"<script type='text/javascript'>";
echo
"alert('Article deja ajouté');";
echo
"</script>";
echo "<META
http-equiv='refresh' content='0;URL=GestionArticle.php'>"; */
echo
"<script>alert('This article is already present inside cart')<script>";
echo
"<script>window.open('GestionArticle.php','_self')<script>";
}else{
$insert_query="INSERT INTO detailpanier (id_article,nbrArticle,ip_adress)
VALUES ($get_article_id,'$ip',0)";

$result_insert = mysqli_query($dbhandle, $insert_query);


echo
"<script>alert('Article is added to cart')<script>";
echo
"<script>window.open('GestionArticle.php','_self')<script>";

/*if
($result_insert) {
// If
the article is successfully added to the cart, display an alert and redirect back
to the previous page
echo
"<script type='text/javascript'>";
echo
"alert('Article ajouté');";
echo
"</script>";
echo
"<META http-equiv='refresh' content='0;URL=GestionArticle.php'>";
}
else {
// If
there is an error adding the article to the cart, display an error message
echo
"Error adding article to cart: " . mysqli_error($dbhandle);
echo
"<script>window.open('GestionArticle.php','_self')<script>";

}*/

?>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

if(isset($_GET['add_to_cart'])){

$get_article_id=$_GET['add_to_cart'];

$select_query="SELECT * FROM detailpanier WHERE ip_adress=$ip and


id_article=$get_article_id";

$result_query=mysqli_query($dbhandle,$select_query);

$num_of_rows=mysqli_num_rows($result_query);

if($num_of_rows>0){

/*echo "<script type='text/javascript'>";

echo "alert('Article deja ajouté');";

echo "</script>";

echo "<META http-equiv='refresh' content='0;URL=GestionArticle.php'>"; */

echo "<script>alert('This article is already present inside cart')<script>";

echo "<script>window.open('GestionArticle.php','_self')<script>";
}else{

$insert_query="INSERT INTO detailpanier (id_article,nbrArticle,ip_adress)


VALUES ($get_article_id,'$ip',0)";
$result_insert = mysqli_query($dbhandle, $insert_query);

echo "<script>alert('Article is added to cart')<script>";

echo "<script>window.open('GestionArticle.php','_self')<script>";

/*if ($result_insert) {

// If the article is successfully added to the cart, display an alert and


redirect back to the previous page

echo "<script type='text/javascript'>";

echo "alert('Article ajouté');";

echo "</script>";

echo "<META http-equiv='refresh' content='0;URL=GestionArticle.php'>";

else {

// If there is an error adding the article to the cart, display an error


message

echo "Error adding article to cart: " . mysqli_error($dbhandle);

echo "<script>window.open('GestionArticle.php','_self')<script>";

}*/

You might also like