PHP - Cookies Not Setting, (not Leading To Next Page)
Hello,
It's as subject says. Here is the code: <? //Config include_once "../../config/config.php"; //Variables $username = $_POST["username"]; $username = mysql_real_escape_string($username); $password = $_POST["password"]; $password = md5($password); //Check for User $query = "SELECT * FROM users WHERE username='$username' AND password='$password'"; $query = mysql_query($query); //If user not found if(mysql_num_rows($query)!="1") { echo "No User Found"; } //If User Found else { while($row=mysql_fetch_array($query)) { $fname = $row["fname"]; $lname = $row["lname"]; $userid = $row["id"]; $admin = $row["admin"]; } setcookie("fname", "$fname"); setcookie("lname", "$lname"); setcookie("userid", "$userid"); setcookie("admin", "$admin"); header('Location: ../../../portal/index.php'); } ?> On the page it forwards to, I write print_r($_COOKIE); Yet it doesn't show my newly set cookies, yet the above snipped does on the script code above. George Similar TutorialsWell this isn't all about cookies or maybe it is, I'm not to sure. On top of this my script has suddenly broke and stops at check.php I'm also not sure how I should go about checking the cookie to identify the user and how to keep other from viewing the output page(s). Code: (index.html) [Select] <html> <head> <title>Deadnode.com</title> <style type="text/css"> img { position:absolute; left:300px; top:130px; z-index:-1; } form { position:absolute; left:365px; top:248px; z-index:0; } </style> </head> <body> <img src="iL0bw.png" /> <form method="post" action="check.php"> <center><table> <tr><td><font face="verdana,arial" size=-1>Username:</td><td><input type="text" size="25" name="user"></td> <tr><td><font face="verdana,arial" size=-1>Password:</td><td><input type="password" size="25" name="pwd"></td> <tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Login"></td></tr> </table></center> </form> </body> </html> Code: (function.php) [Select] <?php function check() { $admin="test"; $pass="test"; if (isset($_POST["user"]) && $_POST["user"] == $admin && isset($_POST["pwd"]) && $_POST["pwd"] == $pass) { header('Location: output.php'); setcookie("usr", "test", time()+3600); else { header('Location: index.html'); } } ?> Code: (check.php) [Select] <?php require('function.php'); check(); ?> Code: (output.php) [Select] <?php require('check.php'); ?> <html> <body> <p>Congrats!</p> </body> </html> I have a script where $site (location of where it's hosted) will either be in the format of a subdomain e.g. 'something.domain.com' or a domain 'domain.com', and the cookies are handled like the following:
ini_set('session.cookie_domain', $site); //for sessions setcookie($name, $value, $expiry, '/', $site, false, true); //for othersMy question is the script's canonical url is non-www and I don't want other subdomains for various reasons (including security) being able to access/read the cookies (e.g. 'www.something.domain.com' or 'www.domain.com' or 'somethingelse.domain.com' or 'www.somethingelse.domain.com'), so would you say the above will work okay (providing $site does not proceed with www. or .)? I have searched around (also referred to php.net) and believe the above will be okay from my understanding - but wanted reassurance as I had read many conflicting/confusing information! Edit: If the above won't work - I thought about maybe setting $site to false (the .htaccess code would enforce access only via non-www)? Edited by newbtophp, 25 January 2015 - 05:03 PM. Hello I'm trying to build a plugin to get my site up to scratch for the new EU laws on cookies coming in place on the 26th What my main goal is a notification that when the users click accept the cookies set on machine but untill a "approval" cookie is found the site shouldn't set any cookies. Ive written this code, which allows me to set & unset a cookies via a form, using php and html, then depending on the submission either set or unset (which is a good start because im a noob!) but: the page needs an extra refresh in order to show the set cookie? does anyone know why or how i can resolve this? kind regards, and thank you Code: [Select] <? $set = $_POST["set"]; if($set == "on") setcookie(EURegulations, $set, time() + (20*365*24*60*60), www.domain.net); else if($set == "off") setcookie("EURegulations", "", time()-3600); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>EU Cookie Plugin</title> </head> <body> <?php if (isset($_COOKIE["EURegulations"])) echo "Cookie Permission " . $_COOKIE["EURegulations"] . "!<br />"; else if(!isset($_COOKIE["EURegulations"])) echo "Cookie Permission off"; else echo "Error no cookie Set"; ?> <form name="setform" method="post" action="<?php echo $_SERVER['$PHP_SELF'];?>"> <button name="set" type="submit" value="on">On</button> <button name="set" type="submit" value="off">Off</button> </form> </body> </html> Hello, I am having issues with getting cookies to function how i'd like them to. My goal is to be able to capture a cookie value from the url if a user comes to my site via something like adwords. An example URL they could come to is http://www.mysite.com?kw=hello I am trying to capture the word 'hello' and tie it to that visitor regardless of where they go on the site. I need to use that value to pass through if they complete a form on my site so that i can track the keyword source. I have included the following as the first line of code on every page of my site: Code: [Select] $kw = $_GET["kw"]; setcookie('kw',$kw); Then, if i go to this url: http://www.mysite.com?kw=hello and then later go to a url like this: http://www.mysite.com/page1.html, i am able to echo out the cookie on page1.html using the following code which is contained in page1.html: Code: [Select] echo $_COOKIE["kw"]; The problem is, if i then refresh page1.html i can no longer echo out the cookie--it disappears. I need the cookie to stay with the user no matter what page they are on within the site and not matter how many different pages they visit. I hope i am explaining myself in a way someone can understand. Perhaps cookies aren't the best way? Should i use sessions instead? Thanks in advance for your help Hi Everyone, I have this small bit of PHP that when you are on a certain page it will add a class called selected Code: [Select] <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <ul id="subnav"> <li><a href="gallery.php?category=Wedding" id="wedding" <?php if ($currentPage == 'gallery.php?category=Wedding') {echo 'class="selected"';} ?>>Wedding Hair</a></li> <li><a href="gallery.php?category=Men" id="mens-styles" <?php if ($currentPage == 'gallery.php?category=Men') {echo 'class="selected"';} ?>>Mens Styles</a></li> <li><a href="gallery.php?category=Women" id="womens-styles" <?php if ($currentPage == 'gallery.php?category=Women') {echo 'class="selected"';} ?>>Women's Styles</a></li> <li><a href="gallery.php?category=Salon" id="salon" <?php if ($currentPage == 'gallery.php?category=Salon') {echo 'class="selected"';} ?>>Salon</a></li> </ul> This is not working I think it's because of the file extenstion 'gallery.php?category=Wedding' is there any way I can get this to work with these extensions Any help would be greatly appreciated Thanks Barry i'm creating a page counter which updates a value in a database each time the page is loaded. I'm trying to make it so that it checks to see if a session has been set, if not, it updates the database, and then sets the session. This way it wont update every time someone refreshes the page. $id=$_GET['id']; if(!isset($_SESSION[$id])){ $_SESSION[$id]= $id; $views = $row['views'] + 1; $update_views=mysql_query("UPDATE topic SET views='".$views."' WHERE topic_id='".$id."'") i want to set the session variable as that of the page id ($id) The problem is that it keeps updating the database everytime the page is reloaded. I'm not sure if i'm setting the session variable correctly. Any ideas would be great Thanks hi, I would like to add a leading 0 to my FOR loop for ($i=0; $i<23; $i++) if($i<10){ $i = 0$i; } { echo "<option value=".$i.">" . $i . "</option>"; } this gives and error: unexpected T_VARIABLE at the moment I have: 0 1 2 3 4 5 6 7 8 9 I would like: 00 01 02 03 04 05 06 07 08 09 I have a db with entries as follows: A001 A002 A003 I would like to loop thru these and print them on screen. Instead of doing: echo A001 echo A002 echo A003 I'd like to find a better way since this database will scale up in the future and may get to A999. Is there a way to increment with leading placeholder zeros? for($x=0 ; $x < mysql_num_rows($myresult) ; $x++){ echo $row['A'.##increment here##']; } Thanks! Looking for the best method to conditionally strip leading zeros for the following situation: $a = array(01, 02, 03, ... 10, 11); $a < 10 ? $a = ? : ''; For the following result: 1, 2, 3, ... 10, 11 Is there a better method than explode? Discovered something very strange with trim() and numbers with leading zeros. Code: [Select] <?php $number = 0456; echo trim($number); ?> That ouputs 302. How the heck does 0456 trimmed turn into 302? Is this a bug? Ok my question is, when they hit the "Play!" button, then I want the php code below to pop up. Like... i think I would use the GET method, but I'm not sure still. I don't think that really matters what method you use, but how do I say IF they click on the "Play" button, then lead them to this code so they can start playing the game. I'm entering this into the database, but I'm just trying to get this code first. I already know how to make it lead to the database and whatnot. <?php session_start(); include("logincheck.php"); ?> <?php include_once("header.php"); ?> <br> Welcome to the Six Dice game. <br><br><b>Instructions</b>: You play this game by randomly rolling a dice. If you land on 1-5, you earn 0 rp. If you land on a 6, you earn 500rp! The game is free so why not give it a shot? <br>You may only play this game 25 times a day! <br><br><form action="sixdice.php?roll" method="post"> <input type="submit" name="playsix" value="Play!" /> </form> <?php if(isset($_POST['playsix'])); $dice = rand(1,6); echo "You rolled a<br /><b>{$dice}</b>\n"; $winnings = "500"; if($dice == 6) { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $username = $cxn->real_escape_string($_SESSION['username']); $sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'"; mysqli_query($cxn,$sql); }?> <FORM ACTION="sixdice.php" METHOD="post"> <INPUT TYPE="submit" VALUE="Roll Again!" /> </FORM> <?php include_once("footer.php"); ?> I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
Dear all, i need help so badly...urgent i have customize a simple e-comm site (from www.phpwebcommerce.com tutorial), when user go checkout page(cart.php) it will show product item, quantity, sub-total , shipping, state and total price. Original from the tutorial using php do calculation but shipping cost is flat rate, i need to calculate shipping cost by state & quantity so that i use JavaScript do the calculation. my shopping cart process : 1. user checkout - go to cart.php (user can update qunatity and select state from this page then update cart) this page is working fine... 2. user enter info - user enter payment and shipping address 3. user continue checkout - go to checkoutconfirmation.php (my problem appear here, the information like quantity, sub-total, shipping cost & total from cart.php won't update here) I'm trying not do confuse myself & do it the eaiser way by using PHP cookies to send the javascript value tocheckoutconfirmation.php but i'm not sure how it work....i'm new to php and javascript, any help will appeciated ! Thank you in advanced !! cart.php Code: [Select] <?php require_once 'library/config.php'; require_once 'library/cart-functions.php'; $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } $cartContent = getCartContent(); $numItem = count($cartContent); $pageTitle = 'Shopping Cart'; require_once 'include/header.php'; // show the error message ( if we have any ) displayError(); if ($numItem > 0 ) { ?> <head> <script type="text/javascript"> <!-- Begin function doMath() { var one = eval(document.getElementById('txtQty[]').value) //one = quantity //alert(one); var price = 0; var state = document.frmCart.state.value; ///////var pd_price = 72; ////////////// var unitPrice = document.getElementById('pd_price').innerText.substring(3); //alert(unitPrice); //alert(one); if(state == "east"){ if (one == 1){ price = 6; } else if (one == 2){ price = 8; } else if (one == 3){ price = 10; } else if (one == 4){ price = 12; } else if (one == 5){ price = 12.50; } else if (one == 6){ price = 13; } else if (one == 7){ price = 14; } else if (one == 8){ price = 0; } } else if(state == "west"){ if (one == 1){ price = 9.30; } if (one == 2){ price = 12; } if (one == 3){ price = 17.25; } if (one == 4){ price = 20; } if (one == 5){ price = 21; } if (one == 6){ price = 22; } if (one == 7){ price = 23.45; } if (one == 8){ price = 0; } } document.getElementById('subtotal').innerText = "MYR" + unitPrice * one; //document.frmCart.amount.innerText=price; document.getElementById('amount').innerText = price; ///amount = shipping //alert("asdf"); var test = document.getElementById('subtotal').innerText; // = one*pd_price; // //alert(test); //alert(one); test = parseInt(test.substring(3)) * one; //alert(test); //document.getElementById('subtotal').innerText = test; //alert(test); //alert("A" + price); //alert(parseInt(test)); //alert(one); document.getElementById('total').innerText = price + unitPrice * one; //total = shipping + subtotal test = "MYR" + test; document.getElementById('ct_qty').innerText = document.getElementById('subtotal').innerText; } //function custRound(x,places) { //return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places) //} // End -->s </script> </head> <body onLoad="MM_preloadImages('../images/'), doMath()" > <tr><td align="center"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td align="center" bgcolor="#b6df51"><table width="800" border="0" cellspacing="0" cellpadding="0"><tr><td align="center"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0"> <tr><form action="<?php echo $_SERVER['PHP_SELF'] . "?action=update"; ?>" method="post" name="frmCart" id="frmCart"> <td align="center" bgcolor="#b6df51"><table width="800" border="0" cellspacing="0" cellpadding="0" > <tr> <td align="left"><img src="images/title_purchase_online.gif" width="280" height="25" /></td> </tr> <tr> <td> </td> </tr> <tr> <td align="center"><table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="800" border="0" cellpadding="0" cellspacing="0" bgcolor="#3b7b37"> <tr> <td width="15"><img src="images/title_box_left.gif" width="15" height="30" /></td> <td width="770"><table width="770" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="170" align="center" class="yellow_txt"><strong>Item</strong></td> <td width="213" align="center"> </td> <td width="141" align="center"><strong class="yellow_txt">Unit Price</strong></td> <td width="106" align="center"><strong class="yellow_txt">Quantity</strong></td> <td width="110" align="center"><strong class="yellow_txt">Total</strong></td> <td width="30" align="center"> </td> </tr> </table></td> <td width="15"><img src="images/title_box_right.gif" width="15" height="30" /></td> </tr> </table></td> </tr> <?php $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); $productUrl = "other_products.php?c=$cat_id&p=$pd_id"; $subTotal += $pd_price * $ct_qty; ?> <tr> <td> </td> </tr> <tr> <td align="center"><table width="770" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="170" align="center" class="yellow_txt"><table width="150" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> </tr> <tr> <td width="116" align="center" valign="top" bgcolor="#b6df51"><a href="<?php echo $productUrl; ?>"><img src="<?php echo $pd_thumbnail; ?>" width="116" height="116" border="0" /></a><a href="<?php echo $productUrl; ?>"></a></td> </tr> <tr> </tr> </table></td> <td width="220" align="left" class="green_txt"><strong><a href="<?php echo $productUrl; ?>" style="text-decoration: none"><font color="000000"><?php echo $pd_name; ?></font></a></strong></td> <td width="128" align="center"><strong class="black_txt" id="pd_price"><?php echo displayAmount($pd_price); ?></strong></td> <td width="112" align="center"><input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>"> <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>"></td> <td width="110" align="center"><strong class="black_txt" id="ct_qty"><?php echo displayAmount($pd_price * $ct_qty); ?></strong></td> <td width="30" align="center" valign="middle"><a href="#"> <img src="images/btn_delete.png" width="16" height="16" border="0" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" /></a> </tr> </table></td> </tr> <?php } ?> <tr> <td> </td> </tr> <tr> <td><table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="13" height="13"><img src="images/text_box_big_left1.gif" width="13" height="13" /></td> <td width="774" height="13" bgcolor="#ffde00"><span class="style10"><img src="images/spacer.gif" width="13" height="13" /></span></td> <td width="13" height="13"><img src="images/text_box_big_right1.gif" width="13" height="13" /></td> </tr> <tr> <td bgcolor="#ffde00"> </td> <td height="50" align="center" bgcolor="#ffde00"><table width="770" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="132" align="center" class="yellow_txt"> </td> <td width="147" align="left" class="green_txt"> </td> <td width="113" align="center"> </td> <td width="102" align="center" class="black_txt"><strong>Sub-total</strong></td> <td colspan="2" align="center"><strong class="black_txt" id="subtotal"><?php echo displayAmount($subTotal); ?></strong></td> <td width="19" align="center" valign="middle"> </td> </tr> <tr> <td colspan="7" align="center" class="yellow_txt"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <!-------------------------------------------- shipping cost---------------------------------------------------> <tr> <td align="center" > </td> <td align="left" class="green_txt"> </td> <td> </td> <td align="center" class="black_txt"><strong>State</strong></td> <td colspan="2" align="center"> <select name="state"> <option value="east" selected>East </option> <option value="west">Peninsular</option> </select> </td> <td align="center" valign="middle"> </td> </tr> <tr> <td colspan="7" align="center" class="yellow_txt"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td align="center" class="yellow_txt"> </td> <td align="left" class="green_txt"> </td> <td align="center"> </td> <td align="center" class="black_txt"><strong>Shipping</strong></td> <td width="131" align="right"> <strong class="black_txt"> MYR</strong><!--<input type="text" name="amount" disabled="disabled" size="17" style="background-color:transparent;" border="none" >--></td> <td width="122" align="left"><strong class="black_txt"> <div name="amount" id="amount"> 0</div></strong></td> <td align="center" valign="middle"> </td> </tr> <tr> <td align="center" class="yellow_txt"> </td> <td align="left" class="green_txt"> </td> <td align="center"> </td> <td align="center" class="black_txt33"> </td> <td colspan="2" align="center" class="black_txt33"> <font color="#FF0000">*Purchases of 8 boxes onwards free delivery charges.</font> </td> <td align="center" valign="middle"> </td> </tr> <!------------------------------------------------------------------------------------------------------> <tr> <td colspan="7" align="center" class="yellow_txt"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td align="center" class="yellow_txt"> </td> <td align="left" class="green_txt"> </td> <td align="center"> </td> <td align="center" class="black_txt"><strong>Total</strong></td> <td width="131" align="right"> <!--<input type="text" name="amount" disabled="disabled" size="17" style="background-color:transparent;" border="none" >--><strong class="black_txt"> MYR</strong></td> <td colspan="2" align="left"><strong class="black_txt" id="total"><?php echo displayAmount($subTotal);// + $shopConfig['shippingCost']); ?></strong> </td> <td width="4" align="center" valign="middle"> </td> </tr> <tr> <td colspan="7" align="center" class="yellow_txt"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td align="center" class="yellow_txt"> </td> <td align="left" class="green_txt"> </td> <td align="center"> </td> <td align="center"> </td> <td colspan="2" align="center"><input type="button" class="update_btn" src="images/btn_update_cart.gif" width="102" height="22" border="0" name="btnUpdate" id="btnUpdate" onClick="doMath()"><!--value="submit"--></td> <td align="center" valign="middle"> </td> </tr> </table></td> <td bgcolor="#ffde00"> </td> </tr> <tr> <td width="13" height="13"><img src="images/text_box_big_left2.gif" width="13" height="13" /></td> <td bgcolor="#ffde00"><span class="style10"><img src="images/spacer.gif" width="13" height="13" /></span></td> <td width="13" height="13"><img src="images/text_box_big_right2.gif" width="13" height="13" /></td> </tr> <tr> <td> </td> </tr> </table></td> </tr> <tr> <?php $shoppingReturnUrl = isset($_SESSION['shop_return_url']) ? $_SESSION['shop_return_url'] : 'other_products.php'; ?> <tr> <td align="center"><table width="340" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td><a href="#"> <img src="images/btn_continue_shopping.gif" width="162" height="22" border="0" onClick="window.location.href='<?php echo $shoppingReturnUrl; ?>';" /></a></td> <?php if ($numItem > 0) { ?> <td width="20"> </td> <td><a href="#"> <img src="images/btn_continue_checkout.gif" width="162" height="22" border="0" onClick="window.location.href='checkout.php?step=1';"/></a></td> <?php } ?> </tr> </table></td> </tr> </table></td> </tr> <tr> <td align="center"> </td> </tr> </table></td></form> </tr> </table></td> </tr> </table> </tr> </table></td> </tr> </table></td> </tr> <?php } else { ?> <?php include("EmptyMSG.php"); ?> <!----<td><table width="550" bgcolor="#b6df51" border="0" align="center" cellpadding="10" cellspacing="0"><p align="center">You shopping cart is empty</p> <p>If you find you are unable to add anything to your cart, please ensure that your internet browser has cookies enabled and that any other security software is not blocking your shopping session.</p> </table></td>---> <?php } ?> </body> </html> checkoutConfirmation.php Code: [Select] <?php /* Line 1 : Make sure this file is included instead of requested directly Line 2 : Check if step is defined and the value is two Line 3 : The POST request must come from this page but the value of step is one */ if (!defined('WEB_ROOT') || !isset($_GET['step']) || (int)$_GET['step'] != 2 || $_SERVER['HTTP_REFERER'] != 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?step=1') { exit; } $errorMessage = ' '; /* Make sure all the required field exist is $_POST and the value is not empty Note: txtShippingAddress2 and txtPaymentAddress2 are optional */ $requiredField = array('txtShippingFirstName', 'txtShippingLastName', 'txtShippingAddress1', 'txtShippingPhone', 'txtShippingState', 'txtShippingCity', 'txtShippingPostalCode', 'txtPaymentFirstName', 'txtPaymentLastName', 'txtPaymentAddress1', 'txtPaymentPhone', 'txtPaymentState', 'txtPaymentCity', 'txtPaymentPostalCode'); if (!checkRequiredPost($requiredField)) { $errorMessage = 'Input not complete'; } $cartContent = getCartContent(); ?> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"> </td> </tr> </table> </td> </tr> </table></td> </tr> <form action="<?php echo $_SERVER['PHP_SELF']; ?>?step=3" method="post" name="frmCheckout" id="frmCheckout"> <table width="900" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td align="center" bgcolor="#b6df51"><table width="800" border="0" cellspacing="0" cellpadding="0"><tr><td align="center"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> </tr> <tr> <td align="center"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" bgcolor="#b6df51"> <!------------------------------COD-------------------------------------> <?php if ($_POST['optPayment'] == 'cod') { ?> <table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="330" align="left"><img src="images/title_purchase_online.gif" width="280" height="25" /></td> <td width="464" align="left" valign="bottom"><img src="images/title_step02.gif" width="245" height="20" /></td> </tr> <tr> <td colspan="2"> </td> <p id="errorMessage"><?php echo $errorMessage; ?></p> </tr> <tr> <td colspan="2" align="center" class="green_txt"><table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#3b7b37"> <tr> <td width="15"><img src="images/title_box_left.gif" width="15" height="30" /></td> <td width="470" align="center" class="yellow_txt"><strong>:: IMPORTANT NOTE ::</strong></td> <td width="15"><img src="images/title_box_right.gif" width="15" height="30" /></td> </tr> </table></td> </tr> <tr> <td colspan="2" align="center"><img src="images/spacer.gif" width="12" height="12" /></td> </tr> <tr> <td colspan="2" align="center"> </td> <p id="errorMessage"><?php echo $errorMessage; ?></p> </tr> <?php } ?> <!-----------------paypal---------------------------------> <?php if ($_POST['optPayment'] == 'paypal') { ?> <tr> <td colspan="2" align="center"><table width="800" border="0" align="center" cellpadding="10" cellspacing="1" class="infoTable"><tr><td><table width="800" border="0" align="center" cellpadding="10" cellspacing="1" class="infoTable"> <tr> <tr> <td width="330" align="left"><img src="images/title_purchase_online.gif" width="280" height="25" /></td> <td width="464" align="left" valign="bottom"><img src="images/title_step02.gif" width="245" height="20" /></td> </tr> <td colspan="2" align="center" class="green_txt"><table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#3b7b37"> <tr> <td width="15"><img src="images/title_box_left.gif" width="15" height="30" /></td> <td width="470" align="center" class="yellow_txt"><strong>:: IMPORTANT NOTE ::</strong></td> <td width="15"><img src="images/title_box_right.gif" width="15" height="30" /></td> </tr> </table></td> </tr> <td colspan="2" align="center" ><table width="500" border="0" cellpadding="0" cellspacing="0" > <tr> <td align="center" class="black_txt33"><p>There will be (3.4% + RM2.00 MYR) PayPal transaction fee for credit card payment</p></td> </tr> </table></td> </tr> </table></td> </tr> </table> </td> </tr> <?php } ?> <!-----------------End of paypal----------------------------> <tr> <td colspan="2" align="center"><table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#3b7b37"> <tr> <td width="15"><img src="images/title_box_left.gif" width="15" height="30" /></td> <td width="470" align="center" class="yellow_txt"><strong>Ordered Item</strong></td> <td width="15"><img src="images/title_box_right.gif" width="15" height="30" /></td> </tr> </table></td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> <tr> <td colspan="2" align="center"><table width="360" border="0" cellspacing="0" cellpadding="3"> <tr> <td align="left" class="green_txt"><strong>Item</strong></td> <td align="right" class="green_txt"><strong>Unit Price</strong></td> <td align="right" class="green_txt"><strong>Total</strong></td> </tr> <?php $numItem = count($cartContent); $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); $subTotal += $pd_price * $ct_qty; ?> <tr> <td align="left" class="black_txt"><?php echo "$ct_qty x $pd_name"; ?></td> <td align="right" class="black_txt"><?php echo displayAmount($pd_price); ?></td> <td align="right" class="black_txt"><?php echo displayAmount($ct_qty * $pd_price); ?></td> </tr> <?php } ?> <tr> <td colspan="3" align="left"><img src="images/spacer.gif" width="12" height="12" /></td> </tr> <tr> <td align="left"> </td> <td align="right" class="green_txt"><strong>Sub-totall</strong></td> <td align="right"><span class="black_txt"><?php echo displayAmount($subTotal); ?></span></td> </tr> <tr> <td align="left"> </td> <td align="right" class="green_txt"><strong>Shipping<br /> </strong></td> <td align="right"><span class="black_txt"><?php echo displayAmount($shopConfig['shippingCost']); ?></span></td> </tr> <tr> <td align="left"> </td> <td align="right" class="green_txt"><strong>Total</strong></td> <td align="right"><span class="black_txt"><?php echo displayAmount($shopConfig['shippingCost'] + $subTotal); ?></span></td> </tr> </table></td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> <tr> <td colspan="2" align="center" class="black_txt"><strong><?php echo $_POST['optPayment'] == 'paypal' ? 'Paypal' : 'Bank-in / Bank Transfer'; ?> <input name="hidPaymentMethod" type="hidden" id="hidPaymentMethod" value="<?php echo $_POST['optPayment']; ?>" /></strong></td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> <tr> <td colspan="2" align="center"><table width="380" border="0" cellspacing="0" cellpadding="0"> <tr> <td ><input name="btnBack" type="button" id="btnBack" onClick="window.location.href='checkout.php?step=1';" class="btn" ></td> <td width="20"> </td> <td><input type="image" src="images/btn_confirm_order.gif" width="132" height="22" border="0" value="Submit" name="btnConfirm" id="btnConfirm"></td> </tr> </table></td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> <tr> <td colspan="2" align="center"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <table width="800" border="0" cellspacing="0" cellpadding="0"><tr></tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </form> </body> </html> thank you for the time and attention Hey Everyone, I just have a quick question. I have a page that has set a cookie called email_success with the value "yes". I now need some code so that when the user goes to a download page, it checks for the cookie and if there is no cookie it redirects to another page. But if there is the cookie it displays the download page. I tried i few things but didn't work. Can anyone help me please!! Thanks George I have this page where I create two cookies with the username and passwords of the users for the website. Code: [Select] $equipa = $_POST['equipa'] ; $pass = $_POST['codigo'] ; setcookie("equipa", "$equipa", time() + 3600) ; setcookie("codigo", "$pass", time() + 3600) ; In the next page, I can have access to the cookie, with this script : Code: [Select] <?php $equipa = $_COOKIE['equipa'] ; echo $equipa ; $pass = $_COOKIE['codigo'] ; echo $pass ; ?> But in this page you have to fill a form and send it, going to a new page. In this new one, with the exact same code, I can't access the cookie. If anyone could please help me and tell me why..... Thanks for the help Hey all, http://www.adamrowden.co.uk/photo-searchr.asp If you visit this link, you'll see on the left side you have a few photos. If you click a photo from that page and then go back to the link i've provided you'll see that it shows you your 'recently viewed photos'. I'm wanting to do exactly that and need some pointers on how i would!? I'd be very grateful for any help Thanks, Jimmy m i was trying to make a new login script and wanted to make point system which i can add points manually to member so i made a new column and named it userpoint i tried many many codes First i used
$_SESSION['userName'] = $username; echo "Welcome ".$_SESSION['userName']."!"; $_SESSION['userpoint'] = $userpoint; echo "you got".$_SESSION['userpoint']."!";the page showed username but didn`t show the points ! i tried then i figured out cookies if(isset($_COOKIE['ID_my_site'])) { setcookie( "userpoint"); $username = $_COOKIE['ID_my_site']; $userpoint = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check)) {this time the page shows both of usernames without mentioning the points ! i changed $userpoint = $_COOKIE['ID_my_site'];to $userpoint = $_COOKIE['Key_my_site']; and it showed the hashed password i want to set a new $_COOKIE so i can get members point to member area is that possible ? the script is still missing secure and salt and the security stuff i`ll add them later i just want to know if is that possible Edited by Ahmedamer, 03 September 2014 - 09:39 PM. Okay im having a problem with cookies so if anyone can help i would be grateful. When you login you can choose how long to stay in for. For testing purposes the choices a Forever 1 Hour 1 Day Never Based on your choice i am setting the cookie expiration as follows: if ($_POST['remember_me'] == '1') { setcookie('remember', time() + 99999999999999); } elseif ($_POST['remember_me'] == '3600') { setcookie('remember', time() + 3600); } elseif ($_POST['remember_me'] == '84600') { setcookie('remember', time() + 84600); } elseif ($_POST['remember_me'] == '0') { setcookie('remember'); } echo $_COOKIE['remember']; } Then for testing I am echoing the cookie at the head of the document: echo "Cookie: " . @$_COOKIE['remember']; The problem is that when the browser is closed the cookie is gone. Only the last option "never" is set as a session cookie which means the others should stay active even when the browser is closed shouldnt they? Anything i have missed here? The code below is the only part of my script failing and I have no clue why. I even tried setting the TestCookie for 352 days. What boggles my mind is that this code used to work and is now failing. Has something changed? $value = "wtf"; setcookie("TestCookie",$value, time()+3600*24); setcookie("user", $name1, time()+14400); setcookie("userid", $uid1, time()+14400); setcookie("coid", $coid1, time()+14400); setcookie("login", "yes", time()+14400); setcookie("status", $status1, time()+14400); |