This is the index page, from which the user is redirected to the payment page where the payment is made. Once the payment is made, I want that the user is then redirected to the success page, which eventually redirects to the details page of the "specific" item for which the payment has been made. $customer['id'] is an integer value determines the unique id of the item, so if we can redirect the user to details.php?id=$customer['id'] then the work is done. However, I can't seem to manage to find a way to do so.
Here's the part of the index in which I am trying to modify $customer['id'] so that it can be easily passed to the details page through the payment page:
<?php
$newID = ($customer['id']);
?>
<div class="card-action right-align">
<a class="brand-text" href="payment.php">more info</a>
</div>`
here's the success page code which is supposed to redirect to :
<?php
include 'index.php';
if(!empty($_GET['tid'] && !empty($_GET['product']))) {
$GET = filter_var_array($_GET, FILTER_SANITIZE_STRING);
$tid = $GET['tid'];
$product = $GET['product'];
} else {
header('Location: payment.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Thank You</title>
</head>
<body>
<div class="container mt-4">
<h2>Thank you for purchasing <?php echo $product; ?></h2>
<hr>
<p>Your transaction ID is <?php echo $tid; ?></p>
<p>Check your email for more info</p>
<?php header('Refresh: 2; URL=details.php?id=$customer['id']');?>
</div>
</body>
</html>
amongst the above code, this is the most important part(must be modified somehow to make it work I guess):
<?php header('Refresh: 2; URL=details.php?id=$customer['id']');?>
can somebody help me out please?
You have problem with quotes in there. they cancel each other out in the wrong place. Call the variable outside single quote marks, cause they cannot process php variables.
<?php header('Refresh: 2; URL=details.php?id='.$customer['id']);?>
Related
This is on file : PurchaseSiteLoggedIn.php
<!DOCTYPE html>
<html lang="en">
<header>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Palm User Login-Registration</title>
<link rel="stylesheet" href="">
</header>
<script src=""></script>
<body>
<?php
session_start();
if(isset($_SESSION['id']) && isset($_SESSION['username'])){
}
else{
header("Location: http://localhost/loginregister.html");
}
?>
</body>
</html>
If the user is not logged in he/she will be redirected to another page.(the loginregister.html)
This code works fine. What I wanna do is replace:
<?php
session_start();
if(isset($_SESSION['id']) && isset($_SESSION['username'])){
}
else{
header("Location: http://localhost/loginregister.html");
}
?>
with DoAnonymousCheck(); (a random name for the function) so that the code looks cleaner
//
Ideally i would want to have the body of the DoAnonymousCheck on a different file.
I tried somthing like:
I added
<script src='DoAnonymCheck.php'></script>
in the PurchaseSiteLoggedIn.php folder.
And in another folder that i called DoAnonymCheck.php I had
<?php
function DoAnonymCheck(){
session_start();
if(isset($_SESSION['id']) && isset($_SESSION['username'])){
}
else{
header("Location: http://localhost/loginregister.html");
}
}
?>
It didnt work though (i guess in <script src></script> you can only add a .js folder)
You can't "import" a PHP script with a script tag, because all PHP code is executed on the server side before it shows up in the client browser. However, you can use include or require to load other PHP scripts. Code Example
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 10 months ago.
This is my PHP code. My backwardCallFunction and forwardCallFunction do not work. The number displayed in:
<div class= 'call-count'>Call Count: <?php echo $_SESSION['callCount'];?></div>
Still the same. Anyone can help me solve the problem?
<?php
session_start();
$_SESSION['callCount'] = 0;
function forwardCallFunction()
{
$_SESSION['callCount']++;
}
function backwardCallFunction()
{
$_SESSION['callCount']--;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet"
href="https://fonts.sandbox.google.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD#20..48,100..700,0..1,-50..200"/>
<title>Document</title>
</head>
<body>
<div class='home-middle-subcontent'>
<div class='to-left' onclick="<?php backwardCallFunction(); ?>"><span class="material-symbols-rounded">keyboard_double_arrow_left</span>
</div>
<div class='call-count'>Call Count: <?php echo $_SESSION['callCount']; ?></div>
<div class='to-right' onclick="<?php $_SESSION['callCount']++; ?>"><span class="material-symbols-rounded">keyboard_double_arrow_right</span>
</div>
</div>
</body>
</html>
Change
<?php
session_start();
$_SESSION['callCount']=0;
to this
<?php
session_start();
if (!isset($_SESSION['callCount']) {
$_SESSION['callCount']=0;
}
Otherwise you will reset the counter every time you access the page.
Once done, you need to rework the html part of your script (javascript and php are not communicating the way you try to do).
Change
<div class='to-left' onclick="<?php backwardCallFunction(); ?>"><span class="material-symbols-rounded">keyboard_double_arrow_left</span>
</div>
to
<a class="to-left" href="?to-left"><span class="material-symbols-rounded">keyboard_double_arrow_left</span></a>
and
<div class='to-right' onclick="<?php $_SESSION['callCount']++; ?>"><span class="material-symbols-rounded">keyboard_double_arrow_right</span>
</div>
to
<a class="to-right" href="?to-right"><span class="material-symbols-rounded">keyboard_double_arrow_right</span></a>
Using the a tag and skinning it as a DIV with CSS is way simpler (and usual) than the opposite way.
Once you have done, you need to read the user action using the uri you get and perform the needed action:
<?php
function forwardCallFunction()
{
$_SESSION['callCount']++;
}
function backwardCallFunction()
{
$_SESSION['callCount']--;
}
session_start();
if (!isset($_SESSION['callCount']) {
$_SESSION['callCount']=0;
}
$action = $_SERVER['QUERY_STRING'];
if ($action == 'to-left') backwardCallFunction();
if ($action == 'to-right') forwardCallFunction();
?><!DOCTYPE html>
The mechanism of php/javascript interaction is just this simple (ajax obfuscate a bit the process but the way it works is the same):
PHP create a page served to the client browser
the user interacts with Links and Buttons and send data to php via the url query string
PHP read the query string (as I have done or via the $_GET / $_POST / $_REQUEST superglobals)
the PHP script take every action needed to check the user input against input data tampering and user misbehavious (aka XSS attack and similar
PHP create a page served to the client browser and so on
Here's what I'm trying to do. I'm trying to echo blog posts stored in my database. Simple enough, but I want them to be redirected to view_post.php to show the full post, when they click on the little preview. Here's my code:
<?php
session_start();
require_once('required/db.php');
$_SESSION['admin'] = false;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>WillWam - Blog</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/style.css" type="text/css">
<link rel="ico" href="assets/favicon.ico">
</head>
<body>
<nav><h2 class="title">The Blog</h2></nav>
<?php
$sql="SELECT id,title,author,body FROM posts ORDER BY id DESC";
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
printf('<div class="row"><div class="row-inner"><p><strong>%s</strong> | %s |</p></div></div>', $row[0],$row[1],$row[2]);
}
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
<div class="top-margin wrapper"><div class="container"><p>Administrator? Click here.</p></div></div>
</body>
</html>
How would I go about making the preview row a link dynamically (such as view_post.php?id=1)? What would I put in view_post.php?
Assumming on $row the id is contained you can create the links like this
printf('<a href="view_post.php?id='.$row['id'].'"> <----just put the id there
And on view_port use the value
<div class="row"><div class="row-inner">
<p><strong>%s</strong> | %s |</p></div></div></a>', $row[0],$row[1],$row[2]);
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 5 years ago.
IK this is prob a dupe, but I cant find any solutions to my code what so ever, no matter what code i add/change, it just wont budge... (NOTE im not using normal php, using a friends version, which yes, is fine and dandy)
<?php
include($_SERVER['DOCUMENT_ROOT'].'/phpAlphaDB/core.php');
?>
<html>
<head>
<link rel="icon" type="image/png" href="../logo.png">
<title> Xenoz Web - Users </title>
<link rel="stylesheet" type="text/css" href="../css/style.php" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<?php
if ($role==0) {
header('Location: http://xenozweb.tk/index.php');
} else {
echo '<script>alert("Hello, '.$username.'. Welcome to the userlist...");</script>';
}
?>
<body>
<div class="navigation">
<div class="navitem"> Home </div>
<div class="navitem"> Register </div>
<div class="navitem"> Login </div>
<div class="navitem"> Users </div>
<div class="navitem"> Jukebox </div>
</div>
</div>
<div class="pagecontent">
<div class="userblock">
<?php
$results = db_read('xenozweb-users', '', 'username');
foreach ($results as $result) {
$u_name = db_column($result, 0);
echo '<div class="users">',$u_name,'</div>';
}
?>
</div>
</div>
</body>
</html>
You're returning a partial response before you set the header. Headers must be sent before a response is sent back to the browser.
Try moving the header('Location: ') function call into the top <?php enclosure like so:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/phpAlphaDB/core.php');
if ($role==0) {
header('Location: http://xenozweb.tk/index.php');
}
?>
<html>
<head>
<link rel="icon" type="image/png" href="../logo.png">
<title> Xenoz Web - Users </title>
<link rel="stylesheet" type="text/css" href="../css/style.php" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php
if ($role != 0) {
echo '<script>alert("Hello, '.$username.'. Welcome to the userlist...");</script>';
}
?>
</head>
<body>
You've already sent data to the browser. you cannot send header() info properly once you've already started to send data payload.
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 7 years ago.
Just to give you a short background, I am working with a referral program and the main feature of it is referring someone.
In my website. I have registration page, login page, successful registration page, referral page and referral list.
For example, if you are a user, you have to register through registration page. If you successfully register on my page, the next page will be the successful registration page. There is a button there to go to the referral page to refer someone.
The problem I encounter is, I register as a new user. So definitely, I filled up all necessary information to registration page, after I successfully register, the next page after that is showing the successful registration page and in that page there is a button that once you click it, it will go to referral form page.
For example, I will now refer someone, so I filled up all information, so when I tried to submit my referral there is an error that prompt at my page
Can anyone tell me which line of my code is triggering this error:
Warning: Cannot modify header information - headers already sent by
(output started at
/home/thecommissioner/public_html/crm/include/Webservices/Utils.php:880)
in
/home/thecommissioner/public_html/crm/modules/Webforms/capture_old.php
on line 97
but the referral added on my referral list, so when I tried to refer again, this error won't show anymore... even if I refer several times, this error didn't show anymore. It just shows on the first referral try of a new created account. I don't know what the problem is.
This just shows on my first try to referring somebody, but after that, when I tried to refer more, this wont show anymore and I already added my referral. Can someone help me to figure this out?
I know there are several lessons there and I've already read different posts in stackoverflow about this and I'm still vague about it. And would you mind telling me what new code I can use instead of my current code? I cannot test if my page is working because of this.
Here's my code:
<!DOCTYPE html>
<?php
include('../include/dbconnection.php');
include('../include/functions.php');
if(!isset($_SESSION))
{
session_start();
}
$empid = $_SESSION['SESS_EMP_ID'];
$conid = $_SESSION['SESS_CONID'];
$fName = $_SESSION['SESS_FIRSTNAME'];
$lName = $_SESSION['SESS_LASTNAME'];
$contactNo = $_SESSION['SESS_CONTACT_NO'];
$mobile = $_SESSION['SESS_MOBILE'];
$email = $_SESSION['SESS_EMAIL'];
$bday = $_SESSION['SESS_BDAY'];
if($conid == '')
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.location.href='index.php';
</SCRIPT>");
}
else
{
//Nothing
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/skeleton.css">
<link rel="stylesheet" href="../css/successReg_style.css">
<link rel="icon" type="image/png" href="../images/cvglogo.png">
<link rel="short icon" href="../images/favicon.ico">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript"></script>
<link rel="stylesheet" href="../css/animate.css">
</head>
<body>
<!--Here the Header goes-->
<?php include('include/logoheader.php'); ?>
<!-- Overall Contect for Responsive Purposes-->
<div class="allcontent">
<div class="row">
<div class="twelve columns" style="margin-top:0%;">
<!-- Here the Main Content goes-->
<div="maincontent">
<center>
<h3>Congratulations and Welcome to the Circle!</h3>
<br>
<div class=" animated zoomIn socialmedia">
<ul>
<li>
<img class="logos" src="../images/tick.png">
</li>
</ul>
</div>
<!-- This is the welcome Introduction -->
<div class="welcome">
<p>Now that you’re part of the most awesome group on the planet, why not share the glory with your friends. There’s no happier
team
player than a team player with his friends.</p>
<span class="hit">Don’t be shy. Hit the button. Refer your friend!</span><br>
<!-- This is Just a GIF arrow down -->
<div class="demo-wrapper">
<div class="html5-dialog">
<div class="gif">
<img src="../images/scroll-down.gif">
</div>
<?php include('GlobalConstant.php'); ?>
<!-- But here goes the button for "I have someone in mind" -->
<a href="<?php echo employee_refer; ?>"><button class="navbutton">I have someone in mind</button>
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Here the footer goes-->
<center><?php include("include/footer.php"); ?></center>
</body>
</html>
The error:
Warning: Cannot modify header information - headers already sent by
(output started at
/home/thecommissioner/public_html/crm/include/Webservices/Utils.php:880)
in
/home/thecommissioner/public_html/crm/modules/Webforms/capture_old.php
on line 97
just shows on my first attempt of referring then after that, when I referred more, the above warning/error didn't show again.
If those warning just shows on my first attempt of referring, why it doesn't show the next time I referring again? It just shows on my first try.
You need to send header before ANY output is sent. That means before that HTML, on top of page.
OR, as RamRider suggested, use output buffering.
Put
ob_start()
On very top of page and
ob_end_clean()
On very bottom
You need to put the session_start() function on top your code. Otherwise sometimes php will throw the exception headers already sent.
<?php
session_start();
include('../include/dbconnection.php');
include('../include/functions.php');
$empid = $_SESSION['SESS_EMP_ID'];
$conid = $_SESSION['SESS_CONID'];
$fName = $_SESSION['SESS_FIRSTNAME'];
$lName = $_SESSION['SESS_LASTNAME'];
$contactNo = $_SESSION['SESS_CONTACT_NO'];
$mobile = $_SESSION['SESS_MOBILE'];
$email = $_SESSION['SESS_EMAIL'];
$bday = $_SESSION['SESS_BDAY'];
if($conid == '')
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.location.href='index.php';
</SCRIPT>");
}
else
{
//Nothing
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/skeleton.css">
<link rel="stylesheet" href="../css/successReg_style.css">
<link rel="icon" type="image/png" href="../images/cvglogo.png">
<link rel="short icon" href="../images/favicon.ico">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript"></script>
<link rel="stylesheet" href="../css/animate.css">
</head>
<body>
<!--Here the Header goes-->
<?php include('include/logoheader.php'); ?>
<!-- Overall Contect for Responsive Purposes-->
<div class="allcontent">
<div class="row">
<div class="twelve columns" style="margin-top:0%;">
<!-- Here the Main Content goes-->
<div="maincontent">
<center>
<h3>Congratulations and Welcome to the Circle!</h3>
<br>
<div class=" animated zoomIn socialmedia">
<ul>
<li>
<img class="logos" src="../images/tick.png">
</li>
</ul>
</div>
<!-- This is the welcome Introduction -->
<div class="welcome">
<p>Now that you’re part of the most awesome group on the planet, why not share the glory with your friends. There’s no happier
team
player than a team player with his friends.</p>
<span class="hit">Don’t be shy. Hit the button. Refer your friend!</span><br>
<!-- This is Just a GIF arrow down -->
<div class="demo-wrapper">
<div class="html5-dialog">
<div class="gif">
<img src="../images/scroll-down.gif">
</div>
<?php include('GlobalConstant.php'); ?>
<!-- But here goes the button for "I have someone in mind" -->
<a href="<?php echo employee_refer; ?>"><button class="navbutton">I have someone in mind</button>
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Here the footer goes-->
<center><?php include("include/footer.php"); ?></center>
</body>
</html>
If you are still experiencing the issue try ob_start() and ob_flush() .. Anyways this stackoverflow article about headers already sent is worth reading though Stackoverflow link