Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I have a code as below I need it to change the PHP page to another page if the conditions are met, if it is not met it needs to send it back to the other page
if($result = mysqli_query($con,$sql)) {
if (mysqli_num_rows($result) >= 1) {
header("test.php");
}
} else {
echo"Wrong";
}
I have tested the above so the string and queries work now when I use the header function to change page nothing happens
I used header function to change the page when I echo a description where the header is I can see the IF function based on the Query
try this code
if($result = mysqli_query($con,$sql)) {
if (mysqli_num_rows($result) >= 1) {
header("location: test.php");//add location:
}
}else{
echo"Wrong";
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
It's late - there's something probably really simple that I'm missing, but I just can't figure it out right now.
My function:
function likes()
{
global $connection;
$stmt = $connection->prepare("INSERT INTO likes (article_id, ip_address) VALUES (?, ?)");
$stmt->bind_param("is", $_GET['id'], $_SERVER['REMOTE_ADDR']);
$stmt->execute();
$result = $stmt->get_result();
if($result)
{
header("location:javascript://history.go(-1)");
}
else
{
exit('Something weird happened');
}
$stmt-close();
}
The function is being called in likePost.php (../../likes/ after http rewrite) with the following link:
<a href='../../likes/" . $post->id . "'><img src='/images/like.png' title='Like this post' alt='Like button' height='32' width='32'></a>
The only thing in likePost.php is
session_start();
include "../db.php";
include "functions.php";
likes();
include "includes/header.php";
In my mind, it SHOULD be working. But when I click the link, I always get a blank page with the words "Something weird happened". But the db was updated no problems.
Can anyone see what I can't seem to?
I just found out it was header("location:javascript://history.go(-1)"); creating the problem. I changed it to ("Location: /"); and there's no more problems. So... I just need to figure out how to go back to the previous page instead of root...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 4 types of users in my system. So i have to include header files using conditions.
I tried below code.
if($this->session->userdata('email_admin')){
include('header_admin.php');
}
if($this->session->userdata('email_zone_manager')){
include('header_zone_manager.php');
}
if($this->session->userdata('email_state_manager')){
include('header_state_manager.php');
}
if($this->session->userdata('email_user')){
include('header_user.php');
}
When i tried with echo something and exit() its working means condition works file but header css and js etc. are not including.
if($this->session->userdata('email_admin'))
{
echo "Admin";
include('header_admin.php');
}
Above code echo "Admin" but header_admin's contents are not including.
You can load views like this...
if(isset($this->session->userdata('email_admin'))){
$this->load->view('header_admin');
}
if(isset($this->session->userdata('email_zone_manager'))){
$this->load->view('header_zone_manager');
}
if(isset($this->session->userdata('email_state_manager'))){
$this->load->view('header_state_manager');
}
if(isset($this->session->userdata('email_user'))){
$this->load->view('email_user');
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need help on how to make an API for PHP. I was trying to make one web server communicate with another webserver through PHP.
I also want it to update MySQL code. I was using $_GET but it was less secure. Here is my code, can you please take a look at it?
<?php
/*
example: website-url-here.com/?command=insert-command-here&password=testing
*/
$command = $_GET["command"];
$password = $_GET["password"];
if ($password == "testing") {
//Was not a good idea, less secure.
//echo eval($command);
//More secure
if ($command == "create-user")
{
//create user command here
}
else if ($command == "delete-user")
{
//delete user command here
}
else
{
die("Command is incorrect");
}
}
echo "Success";
?>
This question is way too open ended to answer in a StackOverflow answer. Try reading up a little on REST, and a lot on PDO, especially in the context of sanitizing user input.
Think about what would happen if somebody called your api with [url]?command=rm -rf .&password=testing
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So I'm using $_GET to capture the URL to use it later but when I use $_GET it wont redirect!
So here's my sample code:
URL : http://localhost/project/active.php/?s=ieugfshd&h=qwuyrbcq&i=1
php code:
<?php
include 'init.php';
$s = trim($_GET['s']);
$h = trim($_GET['h']);
$i = trim($_GET['i']);
$q = key_check($s,$h,$i);
if($q == 1)
{
header("location:password_active.php");
exit;
}
if($q == 0)
{
header("location:login_failed.php");
exit;
}
?>
EDIT:
key_check( ) function
function key_check($k1,$k2,$id)
{
$query = mysql_query("select key1 from users where user_id = '$id'");
$key1 =mysql_result($query,0);
$query = mysql_query("select key2 from users where user_id = '$id'");
$key2 =mysql_result($query,0);
$y=strcmp($k1,$key1);
$z=strcmp($k2,$key2);
if($y || $z == 0)
{
return 1;
}
else
{
return 0;
}
}
Now when I try this, I got "1" but I'm getting
This web page has a redirect loop
But my password_active.php doesn't have any redirects. It's just an html page.
The URL you're using to access to your script is:
http://localhost/project/active.php/?s=ieugfshd&h=qwuyrbcq&i=1
This loads active.php, which does its role and then tries to send the following header :
header("location:password_active.php");
The browser recieves this header, and tries to resolve that relative URL by adding password_active.php after the last slash before the query string (that ?s=xxx string).
So your browser loads:
http://localhost/project/active.php/password_active.php?s=ieugfshd&h=qwuyrbcq&i=1
This loads active.php again, which does its role again and then send again the same header, and that loads this page:
http://localhost/project/active.php/password_active.php?s=ieugfshd&h=qwuyrbcq&i=1
Again. And again. And again. After several tries, your browser understands that something is going wrong and stops.
You should use an absolute URL in your HTTP header:
header("Location: /project/password_active.php");
Also, please note how HTTP headers should be written, according to the standard.
Random notes :
According to the file names, $s and $h are both passwords. You should hash them, and not passing them via the URL.
if($y || $z == 0) is unlikely to work as you think, since it will be evaluated as if y or not z in pseudo code, while you may have wanted if not y and not z for password checking.
Also, good point for calling exit() after a Location header. You should never forget that, as it is very important and may cause some trouble in your scripts if you forget them.
Try removing / after file.php. Like index.php?i=sa
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i am trying to develop a website and i want that after entering correct username and password desired page should open. how i can achieve this.
if(...)
{
// code to verify login...
header("Location: http://page_to_forward_to/");
}
else { ... }
Hope this is what you are looking for
$url = "my/url/here";
Header("Location: $url");
exit();
you can use the header function:
header("location: www.example.com/yourpage.php");
Other possibility is to use javascript:
<script>
window.location = 'yourpage.php';
</script>