PHP - Setting Samesite In Php7.1.x
Hi, In < PHP7.3, is it possible to set the session.cookie_samesite to "none' and secure to do away with the warning messages of chrome ? Thanks.
Similar TutorialsHello
I've heard new PHP version (7) is on its way. Since I didn't found any thread laying around already. I guess, lets discuss it.
Estimated remaining time until early alpha is around a year. And stable release is expected to be in 2016/2017.
Edited by OmegaExtern, 07 August 2014 - 05:02 PM. I have an interface with method: public function foo(string $arg1, string $arg2); With PHP7.4, I can have a class relax the type without errors such as Dog::foo(string $arg1, $arg2) ($arg2 is not required to be a string) I incorrectly thought I could even relax the constraint more such as Dog::foo(string $arg1){} and not even pass $arg2 because extra arguments which exceed a method's placeholders are ignored without error but I received error: Declaration of Dog::foo(string $arg1) must be compatible with AnimalInterface::foo(string $arg1, string $arg2). Are my only options to include $arg2=null in the relaxed methods and label the methods something $dummy1, $dummy2..., or pass them in an array (which I don't wish to do)? Is passing extra parameters to the same method as I am doing considered bad practice, and if so what is considered the correct way? Thanks
<?php declare(strict_types=1); ini_set('display_errors', '1'); echo "PHP Version: ".PHP_VERSION.PHP_EOL; // => PHP Version: 7.4.1 interface AnimalInterface { public function foo(string $arg1, string $arg2); } abstract class Animal implements AnimalInterface { protected string $name; public function __construct(string $name) { $this->name = $name; } protected function test($method, $arg1, $arg2) { echo $method.' '.$this->name.' '.gettype($arg1).' '.gettype($arg2).PHP_EOL; } } class Cat extends Animal { public function foo(string $arg1, string $arg2) { $this->test(__FUNCTION__, $arg1, $arg2); } public function bar(string $arg1, string $arg2) { $this->test(__FUNCTION__, $arg1, $arg2); } } class Dog extends Animal { //public function foo(string $arg1){} //generates an error public function foo(string $arg1, $arg2=null) { $this->test(__FUNCTION__, $arg1, $arg2); } public function bar(string $arg1) { $arg2=$arg2??null; $this->test(__FUNCTION__, $arg1, $arg2); } } $kitty = new Cat("Ricky"); $doggy = new Dog("Mavrick"); $kitty->foo('arg1', 'arg2'); $doggy->foo('arg1', [1,2,3]); //$kitty->bar('arg1', (int)222); //will error using strict mode only $doggy->bar('arg1', (int)222); $kitty->bar('arg1', 'arg2'); $doggy->bar('arg1', [1,2,3]);Quote
PHP Version: 7.4.1
Fatal error: Uncaught Error: Call to undefined method FPDF::TextWithRotation() in C:\laragon\www\arx\fpdf\rot.php:8 Stack trace: #0 {main} thrown in C:\laragon\www\arx\fpdf\rot.php on line 8 this issue is coming in my file don't knw i want to rotate my text in pdf
<?php require('rpdf.php');
$pdf=new FPDF();
$pdf->AddPage(); $pdf->SetFont('Arial','',40); $pdf->TextWithRotation(50,65,'Hello',45,-45); $pdf->SetFontSize(30); $pdf->TextWithDirection(110,50,'world!','L'); $pdf->TextWithDirection(110,50,'world!','U'); $pdf->TextWithDirection(110,50,'world!','R'); $pdf->TextWithDirection(110,50,'world!','D'); $pdf->Output(); ?>
please help me Edited August 11, 2020 by Ali9980
I have used this program for many years without problems. I have not altered the file in any way, so why is this happening? Is it to do with PHP upgrade?😖 Here is the file: <?php include("connect_Verses4Cards.php"); $conn=get_db_conn_verse(); session_start(); $display_block =""; $color=""; $r =""; $g =""; $b =""; $image =""; //Get the Card Variables $Get_Size_sql = "SELECT * FROM `CSize` WHERE `Size` ='".$_POST["CSize"]."'"; $Get_Size_res = mysqli_query($conn, $Get_Size_sql) or die(mysqli_error($conn)); if (mysqli_num_rows($Get_Size_res) < 1) { //this Card does not exist $display_block = "You have selected an invalid Card size. Please try again."; } else { //get the print variables while ($Size_info = mysqli_fetch_array($Get_Size_res)) { $BoxX = stripslashes($Size_info['BoxX']); $Cellw = stripslashes($Size_info['Cellw']); $Cellh = stripslashes($Size_info['Cellh']); $SizeI = stripslashes($Size_info['Size']); $SID = stripslashes($Size_info['SID']); $floatx = stripslashes($Size_info['floatx']); $floaty = stripslashes($Size_info['floaty']); $floatw = stripslashes($Size_info['floatw']); $floath = stripslashes($Size_info['floath']); $ort = stripslashes($Size_info['ort']); } //create the display string $display_block = "$ort"; } //verify the Event exists //$the_id = mysqli_real_escape_string($mysqli, $_SESSION[VID]); $Get_Verse_sql = "SELECT id, Event, Sub_Type, Verse FROM verses WHERE id='".$_SESSION['Test']."'"; $Get_Verse_res = mysqli_query($conn, $Get_Verse_sql) or die(mysqli_error($conn)); if (mysqli_num_rows($Get_Verse_res) < 1) { //this Event does not exist $display_block = "You have selected an invalid Event. Please try again."; } else { //get the Event ID while ($Verse_info = mysqli_fetch_array($Get_Verse_res)) { $Verse = stripslashes($Verse_info['Verse']); } //create the display string $display_block = "$Verse"; //free results mysqli_free_result($Get_Verse_res); mysqli_free_result($Get_Size_res); //close connection to MySQL } mysqli_close($conn); require('fpdf.php'); class PDF extends FPDF { var $B; var $I; var $U; var $HREF; function PDF($orientation='P', $unit='mm', $size='A4') { // Call parent constructor $this->FPDF($orientation,$unit,$size); // Initialization $this->B = 0; $this->I = 0; $this->U = 0; $this->HREF = ''; } function SetStyle($tag, $enable) { // Modify style and select corresponding font $this->$tag += ($enable ? 1 : -1); $style = ''; foreach(array('B', 'I', 'U') as $s) { if($this->$s>0) $style .= $s; } $this->SetFont('',$style); } } $color = $_POST['color']; $r = substr($color,0,3); $g = substr($color,3,3); $b = substr($color,6,3); $image=$_POST['image']; $pdf = new PDF($ort,'mm','A4'); $pdf->AddPage(); $pdf->AddFont('French Script MT','','/frscript.php'); $pdf->AddFont('Batavia','','Batavia_.php'); $pdf->AddFont('Algerian','','Alger.php'); $pdf->AddFont('Bladerunner','','BLADRMF_.php'); $pdf->AddFont('Brush Script','','BRUSHSCI.php'); $pdf->AddFont('Helterskelter','','Helte___.php'); $pdf->AddFont('Justice','','Justice_.php'); $pdf->AddFont('Magneto','','MAGNETOB.php'); $pdf->AddFont('Old English','','OldEngl.php'); $pdf->AddFont('Sneakerhead Outline','','Sneabo__.php'); $pdf->AddFont('Trendy','','Trendy__.php'); $pdf->AddFont('Vladimir Script','','VLADIMIR.php'); $pdf->SetLeftMargin('float0'); $pdf->SetTextColor($r,$g,$b); $pdf->SetFont($_POST['fontface'],'',$_POST['font']); $pdf->SetXY($BoxX, $_POST['Top']); $pdf->Image($image,$floatx,$floaty,$floatw,$floath,'',''); $pdf->MultiCell($Cellw,$Cellh,$display_block,'' ,'C'); //$pdf->SetDisplayMode('fullpage',''); $pdf->SetFont(''); $pdf->Output('verse.pdf','D'); //end: ?>
Please can some one help me. We have upgraded php and not i cant get the php page to correctly redirect the user to the login page if the user has not logged in and the get it to redirect to the index page. So the form sequence is as follows. User connects to index page, user clicks on link to add or delete data in mysql database, page must redirect to login page if user has not logged in, once logged in login page must redirect to add or delete page depending on the link clicked on. Addins and deleting data to the mysql database table works fine.
Below is the add,php page.
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
session_start(); //start session. if(!isset($_GET['name'])){//added this to check if name is sent include('database.php'); if (!isset($_SESSION["user.id"]) && $_SESSION["user.id"] !="") { } else{ header("Location: login.php"); }
if($_POST['action']) {
include('email.php'); $address=""; $name=$_POST['name']; $extension=$_POST['extension']; $department=$_POST['department']; $phone=$_POST['phone']; $email=$_POST['email'];
$sql = "INSERT INTO users (ID, Name, Email, Extension, Phone, Department) VALUES (NULL, '$name', '$email', '$extension', '$phone', '$department')";
if ($conn->query($sql) === TRUE) echo "New record added"; else echo "Error: " . $sql . "<br>" . $conn->error; $conn->close(); }
?>
<style type="text/css"> <!-- form { font-family: "Courier New", Courier, mono} body { font-family: "Times New Roman", Times, serif} --> </style>
<center><form action="" method="POST"> Name:<br><input type="text" name="name" required pattern=".*[ ].*" title="Please enter Name and Surname." ><br /> Email:<br><input type="text" name="email" required placeholder="@alpinemotors.co.za" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" title="Must be a valid email address, eg: user@mail.co.za" ><br /> Extension:<br><input type="text" name="extension" required pattern="^\d{4}( \/ \d{4})?$" title="Please Enter the Extension Number"><br /> Phone:<br><input type="text" name="phone" pattern="^\d{3} \d{3} \d{4}$" title="Please enter a valid Cellphone Number, eg. 083 511 9213"><br /> Department:<br> <select name ="department"> <option value="ADMIN">ADMIN</option> <option value="FINANCIAL MANAGER">FINANCIAL MANAGER</option> <option value="AFTER-SALES DIRECTOR">AFTER-SALES DIRECTOR</option> <option value="ALPINE SALES DIRECTOR">ALPINE SALES DIRECTOR</option> <option value="DEALER PRINCIPAL">DEALER PRINCIPAL</option> <option value="AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)">AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)</option> <option value="BANDIT">BANDIT</option> <option value="BIDTRACK">BIDTRACK</option> <option value="WORKSHOP BOOKINGS">WORKSHOP BOOKINGS</option> <option value="CLEANERS">CLEANERS</option> <option value="COMMERCIAL SALES DIRECTOR">COMMERCIAL SALES DIRECTOR</option> <option value="WORKSHOP WASHBAY">WORKSHOP WASHBAY</option> <option value="FINANCE AND INSURANCE OFFICE">FINANCE AND INSURANCE OFFICE</option> <option value="FINANCE AND INSURANCE MANAGER">FINANCE AND INSURANCE MANAGER</option> <option value="IT DEPARTMENT">IT DEPARTMENT</option> <option value="MARKETING DIRECTOR">MARKETING DIRECTOR</option> <option value="MARKETING DEPARTMENT">MARKETING DEPARTMENT</option> <option value="MASTER CARS SALES">MASTER CARS SALES</option> <option value="MASTER CARS SALES MANAGER">MASTER CARS SALES MANAGER</option> <option value="PREP DEPARTMENT">PREP DEPARMENT</option> <option value="NUMBER PLATES">NUMBER PLATES</option> <option value="PANELBEATER - EASIFIX - CAR CARE">PANELBEATER - EASIFIX - CAR CARE</option> <option value="PARTS MANAGER">PARTS MANAGER</option> <option value="PARTS">PARTS</option> <option value="PARTS DISPATCH">PARTS DISPATCH</option> <option value="PARTS TELESALES">PARTS TELESALES</option> <option value="TRADE SALES MANAGER">TRADE SALES MANAGER</option> <option value="WASHBAY">WASHBAY</option> <option value="MASTER CARS PREP AND ORDERS">MASTER CARS PREP AND ORDERS</option> <option value="NEW CARS ADMIN AND STOCK CONTROL">NEW CARS ADMIN AND STOCK CONTROL</option> <option value="NEW CARS SHOWROOM">NEW CARS SHOWROOM</option> <option value="NEW CARS SALES MANAGER">NEW CARS SALES MANAGER</option> <option value="WORKSHOP SERVICE ADVISORS">WORKSHOP SERVICE ADVISORS</option> <option value="WORKSHOP">WORKSHOP</option> <option value="WORKSHOP FOREMEN">WORKSHOP FOREMEN</option> <option value="WAREHOUSE">WAREHOUSE</option> <option value="WARRANTY & CLAIMS">WARRANTY & CLAIMS</option> <option value="WORKSHOP DRIVERS">WORKSHOP DRIVERS</option> <option value="WORKSHOP MANAGER">WORKSHOP MANAGER</option> </select> <br /> <br><input type="submit" name="action" value="Submit"> <input type="reset" value="Reset"> </form> <a href="index.php">Extension List</a> </center> </html> }
Below is the login.php
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
session_start(); // Starting Session $error = ''; // Variable To Store Error Message if (isset($_POST['submit'])) { if (empty($_POST['username']) || empty($_POST['password'])) { $error = "Username or Password is invalid"; } else{ // Define $username and $password $username = $_POST['username']; $password = $_POST['password']; // mysqli_connect() function opens a new connection to the MySQL server. $conn = mysqli_connect("localhost", "root", "Pr1v@cY", "T-List_VW"); // SQL query to fetch information of registerd users and finds user match. $query = "SELECT * from UserName where userName=? AND pass=? LIMIT 1"; // To protect MySQL injection for Security purpose $stmt = $conn->prepare($query); $stmt->bind_param("ss", $username, $password); $stmt->execute(); $stmt->bind_result($username, $password); $stmt->store_result(); if($stmt->fetch()) //fetching the contents of the row { $_SESSION['login_user'] = $username; // Initializing Session header("location: index.php"); // Redirecting To Profile Page } mysqli_close($conn); // Closing Connection } ?>
<!DOCTYPE html> <html> <head> <title>Login Form in PHP with Session</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="login"> <h2>Login Form</h2> <form action="" method="post"> <label>UserName :</label> <input id="name" name="username" placeholder="username" type="text"> <label>Password :</label> <input id="password" name="password" placeholder="**********" type="password"><br><br> <input name="submit" type="submit" value=" Login "> <span><?php echo $error; ?></span> </form> </div> </body> </html>
I have been at this for several hours..
<?php ?> I keep getting: Parse error: syntax error, unexpected '?>', expecting ',' or ')' in C:\Apache24\htdocs\mysql_connect.php on line 4 I have tried copy and paste of mysqli_connect from several different web pages, nothing works. PHP is installed correctly, I have a db in MySQL, and Apache is installed with no errors. what the... Edited March 31, 2019 by eljaydeetypo I have a huge application(multi-year) where I do the normal $varX= $var1 + $var2. I get Warning: A non-numeric value encountered because var1 or var 2 are string. I know the right thing will be to intval(), but I just cant go over so much of the application. I read to just disable warning, but I think thats worst because I will not be able to see new warnings. Is there any php.ini solution were php can work as before on math operations? I guess I can ini_set on all the old files and dont do it on the new ones). If there is another accepted solution, please let me know Thank you
can anyone tell me why $username is not setting properly? the password is, but $username is no. it is setting as blank: Code: [Select] if ($_POST['go']) { //Connect to the database through our include if ($_POST['logid'] == ";5757120050531338739=49121200000?"){ $username="oldcheney"; $username = stripslashes($username); $username = strip_tags($username); $username= strtolower($username); $username = mysql_real_escape_string($username); $password="password";} else if($_POST['logid']==";5757120050531338721=49121200000?"){ $username="yankeehill"; $password="password";} else if($_POST['logid']=="%6277202936423578^00000000^X?"){ $username="holdrege"; $password="password";} $password = md5($password); I made a website in PHP mvc framework. Now I want to remove "public" keyword from URL. I tried by removing require "../app/init.php"; these dots and bringing htaccess & index.php file in root directory. But it doesn't work. I searched on google but didn't find anything. Here is my index page code: Quote
<?php require "../app/init.php"; $app = new App();
and my htaccess code: Quote RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f Please give me a solution to it. Thank you Hi, I'm trying to set cookie but all in vain. I've already posted my php code in my last post. "COOKIE PROBLEM". I think there is nothing wrong with code. may be i need to enable to load some library or something in xampp. Is there anyone who knows what setting do i need to do for enable cookies and in which file? Please help I am trying to make a login using cookies, I had been using sessions but i need to use cookies for it now. I have a page called login.php, and i use ajax to login. It seems to be setting the cookie and printing the value of it out when i login, however that's about it. When i'm reading the cookie on other pages it doesn't appear to recognize a cookie. However, If i set the cookie on just a regular index page it has no problem with setting it and reading it. it works fine when i do that. This is how i set the cookie on the login page (also the exact code i used to test setting it on the index page): $expire=time()+60*60*24*30; setcookie("id", $dbid, $expire); $session = $_COOKIE['id']; then to read it on other pages i just use: $session = $_COOKIE['id']; I've been working on this for the last few hours and haven't had much luck. Basically, every time you visit the index of my site a random image is shown. The images are stored in a directory, and i use a table to hold the id, name, and url of each image. When the index page is loaded a random int is chosen, and the id equal to the int prints the corresponding url for the image. Now i'm trying to add the id into the url, "domain.com?img=1". I also need this url to always refer to the image in row 1. My table is called uploaded_images and the columns are id(primary key), name, url. I'm pretty lost, any help is greatly appreciated. Hi I was wondering how I could set up a time mod to set time 3 times per hour. DROP TABLE IF EXISTS og_updateattacks; CREATE TABLE og_updateattacks ( lasttime int(20) default NULL, id int(11) NOT NULL auto_increment, PRIMARY KEY (id) ) TYPE=MyISAM; That is what I got, but I want it so users can attack at random times per hour. hello, ok if i set a Global on index.php (wwwroot/admin/index.php) it works Code: [Select] $page1='hello from page1 on index'; global $page1; echo $page1; i can echo $page1 on other pages like (wwwroot/admin/pages/home.php) and it will echo out "hello from page1 on index". GREAT but if i write a Global on (wwwroot/admin/pages/home.php) it does not work. i also can not echo it out on any other page Code: [Select] $page2='hello from page2 on home'; global $page2; echo $page2; why is this ??? Well 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> Hello, My latest issue is with a login page I am trying to set a cookie for. I have deduced that it it pulling my info out of my database correctly. It does not give any errors for username or password when they are entered correctly but when I get to the end of the script where I would like to set a cookie and redirect to a new page it just stays on the same page and appears as if it is loading but nothing happens. After I stop the browser and attempt to reload the page it gives me an error saying the page cannot be displayed. Do I need to specify anything before I can have the following code work or is it that it is clashing somewhere else along the way? Code: [Select] <?php else { // if login good set cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: http://example.com/"); die(); } ?> If I remove this code and simply leave the redirect as shown above, it works. But that defeats the purpose of the script as on the redirected page there has to be a cookie set to display it. Any help would be appreciated v=$("#txtusername"); $.post('../actions/check.php',{user:v.val().toLowerCase()},function(d){ if(d=='available'){ $("#usernamemessage").html("<span style='color:green;'>Username is available</span>"); }else if(d=='not-available'){ $( "#txtusername" ).effect( "shake" ); $('#txtusername').css('border', 'solid 2px blue'); var iserror = '1' alert(iserror); } }); alert(iserror);The first alert displays '1', however, the second displays 'undefined'. Why is this? Thanks I have created my lottery script. At the moment i simply have the time() function being used where the draw will happen. Im wondering if your able to get rid of that and just choose a particular time where i want the draw to happen. I want the draw to be done at 4pm everyday. (in GMT) Is this possible? and what would the right code be for it. hi i wants to disable open_base_dir for my folder /home/admin/mysite.com/myfolder/ so in myfolder script i could use CURLOPT_FOLLOWLOCATION I can disable open_base_dir in my kloxo panel but i would like to use it this way, I modified my php.ini file and set this path open_basedir = /home/admin/mysite.com/folder/ but still i get error while using CURLOPT_FOLLOWLOCATION Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in Please any help on how to disable that in /myfolder.? using Centos 5 Thanks HI all i have the following code: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if (session_status() == PHP_SESSION_NONE) { session_start(); } if (!isset($_SESSION['user_name'])){ header("location: index.php"); } mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); include '../_includes/dbconn.php'; if($_SERVER['REQUEST_METHOD']=='POST'){ if(isset($_POST['delete-equipment-button'])){ $eid = $_POST['EM-id']; $stmt = $conn->prepare(" SELECT a.equipment_id, b.equipment_name from ssm_equipment_order a inner join ssm_equipment b on a.equipment_id = b.equipment_id where a.equipment_id = ? "); $stmt->bind_param('i', $eid); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($eid, $eqname); $stmt->fetch(); $instances = $stmt->num_rows; $_SESSION['eqname']="$eqname"; if($instances>0){ $_SESSION['updateEquipment']="is being used in an active order and cannot be deleted"; header("location: ../equipment-list.php"); }else{ $_SESSION['updateEquipment']="has been successfully deleted"; $stmt = $conn->prepare(" DELETE FROM ssm_equipment WHERE equipment_id = ? "); $stmt->bind_param('i', $eid); $stmt->execute(); var_dump($_SESSION); // header("location: ../equipment-list.php"); } } } ?> The session variable eqname gets set properly when the delete fails (the first half of my if). When i get to the else, the session does not set a value. I assumed that it was because the item whose name i am trying to get is being deleted but i thought this would happen after i have set the session variable and therefore be preserved for when i get back to the equipment list? As always, i appreciate your help. |