I have a form on frontend page that after submiting should redirect to a page that API returns but I must redirect first to a thank you page and then after some seconds should redirect to the page that the API returns.
this is so far what I have tried but it only waits for the second refresh.
if(isset($result_array['status']) && $result_array['status'] == true)
{
$autologin_url = $result_array['data'] . PHP_EOL;
$signup_result = true;
header("refresh: 5; url = fakeurl.com/thanks.php");
header("refresh: 15; url = $autologin_url");
}
else
{
echo $result;
$signup_result = false;
header('location: fakeurl.com/?report=signup_error');
}
This is what brombeer meant by the redirect:
if(isset($result_array['status']) && $result_array['status'] == true)
{
$autologin_url = $result_array['data'] . PHP_EOL;
$signup_result = true;
header("refresh: 5; url = fakeurl.com/thanks.php");
}
else
{
echo $result;
$signup_result = false;
header('location: fakeurl.com/?report=signup_error');
}
And Paste this in your thanks.php Script:
header("refresh: 15; url = $autologin_url");
Related
I have a PHP application (a request form) that first checks for an active $_SESSION before a user can access the site. Because of the timeout period set for this form there is rarely an active session. Here's the check:
if (isset($_SESSION['samlUserdata'])) {
$attributes = $_SESSION['samlUserdata'];
$user_department = $attributes['department'];
$user_email = $attributes['email'];
$user_employee_id = $attributes['employee_id'];
$user_full_name = $attributes['full_name'];
}
...and here is the else {} that I use to grab the REQUEST_URI:
else {
if (isset($_SERVER['REQUEST_URI'])) {
$referer = $_SERVER['REQUEST_URI'];
$redirect = "https://myinternalwebsite.net$referer";
}
header("Location: https://myinternalwebiste.net/confirm_auth.php?sso");
}
...and last, here is what I do with the $_GET
if (isset($_GET['sso'])) {
if (isset($redirect)) {
$auth->login($redirect);
} else {
$auth->login("https://myinternalwebsite.net/");
}
}
However, once my session is killed I am never properly routed back to the URL set in the ['REQUEST_URI'], I am always just dumped onto the internal site's front page. I have troubleshooted this on and off for some time over the last week, to no avail. I've tried other variables in the $_SERVER array as well, such as ['REDIRECT_URL'].
I'm at a loss, and I'm sure this fairly simple for anyone with more experience than myself... so I am all ears and eager to learn.
EDIT:
Thank you for the comments below. Per your advice I will add the entirety of my code here, removing only the unnecessary parts. (And yes, I appreciate the tip to flip the initial (isset()) to (!isset(). Thank you for that.)
<?php
session_start();
$auth = new OneLogin\Saml2\Auth($saml_settings);
if (isset($_SESSION['samlUserdata'])) {
$attributes = $_SESSION['samlUserdata'];
$user_department = $attributes['department'];
$user_email = $attributes['email'];
$user_employee_id = $attributes['employee_id'];
$user_full_name = $attributes['full_name'];
} else {
if (isset($_SERVER['REQUEST_URI'])) {
$referer = $_SERVER['REQUEST_URI'];
$redirect = "https://example.net$referer";
}
header("Location: https://example.net/confirm_auth.php?sso");
}
if (isset($_GET['sso'])) {
if (isset($redirect)) {
$auth->login($redirect);
} else {
$auth->login("https://example.net/");
}
} else if (isset($_GET['slo'])) {
$auth->logout();
} else if (isset($_GET['acs'])) {
$auth->processResponse();
$errors = $auth->getErrors();
if (!empty($errors)) {
echo '<p>', implode(', ', $errors), '</p>';
}
if (!$auth->isAuthenticated()) {
echo "<p>Not authenticated!</p>";
exit();
}
$_SESSION['samlUserdata'] = $auth->getAttributes();
if (isset($_POST['RelayState']) &&
OneLogin\Saml2\Utils::getSelfURL() != $_POST['RelayState']) {
$auth->redirectTo($_POST['RelayState']);
}
} else if (isset($_GET['sls'])) {
$auth->processSLO();
$errors = $auth->getErrors();
if (empty($errors)) {
echo '<p>Sucessfully logged out!</p>';
} else {
echo '<p>', implode(', ', $errors), '</p>';
}
}
?>
I've got a 'shoppingcart' page and if they modify any values there and then click on 'order' i want the session to actually store the information before i header to the next page, however it seems that the $_SESSION variable does not save it before starting.
I have tried the following:
Solution 1:
$_SESSION['winkelwagen'] = $winkelwagen;
session_write_close();
header("Location: checkout.php");
Solution 2:
$_SESSION['winkelwagen'] = $winkelwagen;
header("Location: checkout.php");
exit();
However, neither of these seem to work for me, i have tried looking at the following stackoverflow topics too:
PHP: session isn't saving before header redirect
Header Not Working With Sessions
however neither of these work, this is my code:
$header = false;
if(isset($_POST['moveForward'])) {
foreach($winkelwagen as $key => $val) {
if (isset($_POST['aantal' . $val['artnr']])) {
if (isset($_POST['verpakking' . $val['artnr']])) {
$verpakking = $_POST['verpakking' . $val['artnr']];
$aantal = intval($_POST['aantal' . $val['artnr']]);
if ($val['amount'] !== $aantal) {
$val['amount'] = $aantal;
$winkelwagen[$key]['amount'] = $aantal;
}
if ($val['verpakking'] !== $verpakking) {
$val['verpakking'] = $verpakking;
$winkelwagen[$key]['verpakking'] = $verpakking;
}
$header = true;
}
}
}
$_SESSION['winkelwagen'] = $winkelwagen;
session_write_close();
if($header) {
header("Location: checkout.php");
exit();
}
}
Any help would be appreciated!
I am trying to exclude a css file from the home page of my site. We load the stylesheet with the header.php, so I am trying to not load it in the homepage.
this is my following code.
$hm == 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ($hm == "home.php") {
echo "";
} else {
echo "yesstylesheet.css";
}
If do you mean home page - main page of your site, than you can try to use follow code
if ($_SERVER['REQUEST_URI']!="/")
{
echo "connect ccs here";
}
Use this snippet
$hm = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$hm1 = strrev($hm);
$hm2 = substr($hm1, strpos($hm1, "/") + 1);
$hm3 = "/".$hm2;
$hm4 = str_replace($hm3,"",$hm1);
$hm = strrev($hm4);
if ($hm == "home.php") {
echo "";
} else {
echo "yesstylesheet.css";
}
Now i want to continuous redirect my site.
Example: Visitor go to: MyDomain/abc?id=1
They will be redirect 302 to: MyDomain/RandomString1
and continue Redirect to MyDomain/RandomString2
and continue:.... until to MyDomain/RandomString10
with Random string is random string and:
RandomString1 to 10 is not exist.
Please help me. Bellow attachment is demo
Here is demo image
Not exactly sure what your looking for but as i understand the question this is what i have to offer
<?
$numberofstrings = 1;
$i = $numberofstrings;
$string = "url";
while($i < $numberofstrings){
$i++;
$currentString = $string . "?id=" . $i;
header("Location: $currentString")
}
$id = $_GET['id'];
if($_GET['id'] == 1){
header("Location: url");
} elseif($id == 2){
header("Location: url2");
}
?>
Is it possible to determine what to show depending on the URL?
I have an index file which is:
<?php include './includes/header.php'; ?>
<?php include './includes/menu.php'; ?>
<?php include './includes/content.php'; ?>
<?php include './includes/sidebar.php'; ?>
<?php include './includes/footer.php'; ?>
Note: I have different "content.php"'s
Is it possible to do something like:
If Url = url {
show only content for the url
}
and then have case system like
case: home.php
show some
etc
I know Wordpress can do it. Is it possible with PHP and MySQL and HTML?
EDIT: Instead of content.php i would want show the desired HTML code gotten from my db
Use this function to see your current page. Then use the "switch" case for proper include file:
## Get Current Page / Section
function cur_page()
{
$cur_page='';
if(isset($_SERVER['PHP_SELF']) && $_SERVER['PHP_SELF']!='')
{
$temp_var1 = explode('/', $_SERVER['PHP_SELF']);
$cur_page = $temp_var1[count($temp_var1)-1];
}
else if(isset($_SERVER['SCRIPT_NAME']) && $_SERVER['SCRIPT_NAME']!='')
{
$temp_var1 = explode('/', $_SERVER['SCRIPT_NAME']);
$cur_page = $temp_var1[count($temp_var1)-1];
}
else if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!='')
{
$temp_var1 = explode('/', $_SERVER['REQUEST_URI']);
$cur_page = $temp_var1[count($temp_var1)-1];
$temp_var2 = explode('?', $cur_page);
$cur_page = $temp_var2[0];
}
else if(isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME']!='')
{
$temp_var1 = explode('/', $_SERVER['SCRIPT_FILENAME']);
$cur_page = $temp_var1[count($temp_var1)-1];
}
return $cur_page;
}//end func.....
Querying from database.
I don't recommend MySql, and I hope you learn PDO instead, but just
for this example
function get_me_title($page) {
$query = "SELECT * FROM title WHERE title = $page";
$result = mysql_query($query);
foreach($result as $row) {
return $row[$page];
}
}
Now, you can use function .get_me_title('whatever') to query from database, and echo below
if(isset($_GET['page_id'])) {
$page = $_GET['page_id'];
switch($page) {
case "contact";
echo get_me_title('contact');
break;
case "about";
echo get_me_title('about');
break;
case "portofolio";
echo get_me_title('portofolio')
break;
default:
echo 'you are in home page';
}
}else {echo '404 ERROR! The Page you have requested does not exist';}
Instead of including content.php, you can include needed page.
For example, if You build Your urls, where, for example, $_GET['page'] will refer to needed page, then simply You can do this.
$availablePages = array('default' => 'home', 'about');
if (isset($_GET['page']) && in_array($_GET['page'], $availablePages) {
$page = $_GET['page'] . '.php';
} else {
$page = $availablePages['default'] . '.php';
}
include $page;