PHP - Page Won't Redirect To Https Once Ssl Is Actually Applied To The Site
This is probably some silly mistake but I can't figure out why this code isn't working. I put this at the top of my php page:
Code: [Select] <?php $https_url = 'https://somesite.com'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'off' ) { header('location: ' . $https_url); exit; } else if ( !isset( $_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] == 443 ) { header('location: ' . $https_url); exit; } ?> When I was just trying this code out it worked and redirected to https. No errors no infinite loops...it worked perfectly. However, once our server guy actually applied the SSL to the page, the code stopped working and I get the error "The page must be viewed over a secure location." It throws the error before it processes anything on that page. I found the code online on another help forum and it worked for everyone else, so what am I doing wrong? I also tried a different version of the code that also works for everyone else but got the same error. Thanks for your help! Similar TutorialsHey Guys, I have a question here and I'm strugling with it, what I am trying to do is redirecting the user as soon as he opens the page to a HTTPS pagefor example. I have a really long URL for my email loginpage so instead of giving user long loink with port number and stuff I have this address "http://company.com/mail" and actualy under this mail directir there is a index.php with this code Code: [Select] <?php header('Location: https://ssl.company.com/crm/webmail/this/location'); exit; exit(); ?> it works great but the problem is it send the user to the NONE-Secure page (HTTP) instead of the secure... Does anyone know how can I go around this?! Thanks Okay, my organanization has a page that we really need to autodirect to https:// in case anyone manually types in the http:// version. I've tried this (among many others) and it just sits there like a knot on a log: Code: [Select] <?php header( "Location: https://www.mywebsite.com/myfile.php" ) ; ?> Any ideas? It just simply doesn't redirect. It just sits there in its http:// format. I've also tried numerous other methods. None of them worked, either, but this is the simplest. Thanks! This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359577.0 Hi guys, We have an independent billing system that we use to track payments. I want to write a PHP script to automatically post a payment to the billing system. I went into the billing system, hit "View source" and got the link + required variables that will allow me to simulate entering a payment. The problem is that it's asking me to enter my credentials everytime I try to simulate the payment. Is a module or something that will automatically enter my credentials in this HTTPS site? Thanks Hi, I am trying to make a registration form for users. The registration is for a seminar introducing a particular system for them. This (web based) system is merely a remote website. But in order for the users to actually use the system at the seminar, they HAVE to have logged in on the system in advance/prior to the seminar at least once. So in my registration form I want to include a curl login of the system, which should be invisible to the users. Hence I don't want to open a popup loading the system/remote site - I would like for this to happen without the users knowing it. So they enter username and password, Curl then does the login and then returns either "Succes! You were logge in!" or "There was an error. You were not logged in!". I have no use for additional information from the remote site - the only thing is that they should login this once - that's it. My code is below - and it works if the remote site is NOT using https (that is http ;-)) but if the remote site IS running https I get no message back. The line "if (stristr($result, "loginerrors"))" is set because the remote site includes the keyword "loginerrors" if you weren't logged in properly. Any suggestions? <?php $post_data['username'] = 'something@domain.com'; $post_data['password'] = 'MyPassword'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //create cURL connection $curl_connection = curl_init('https://www.domain.com/login.php'); //set options curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); //set data to be posted curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //perform our request $result = curl_exec($curl_connection); if (stristr($result, "loginerrors")) { echo "There was an error. You were not logged in!"; }else{ echo "Succes! You were logge in!"; } //close the connection curl_close($curl_connection); ?> I want to make sure that a specific page (login.php) only has stuff from my https and none from my (or other) http sites. How can I do this? Hi friends. I have a problem with https about $_SESSION in php last time my website is working correctly with http but after change to https I can send value of session to another page
login.php session_start(); $_SESSION['user_ID'] = 8;
Action.php session_start(); echo "User ID = " . $_SESSION['user_ID'] ; //// It's not show any thing
Thank you very much for your help Hi, Ive got a script to redirect some traffic from one site to another as follows: Code: [Select] $checker = $_SERVER['HTTP_REFERER']; if($checker == "http://siteone.com) { header("Location: http://www.sitetwo.com"); } It works fine but when the URL is like site.com/anotherpage.php it dosen't redirect. How can i redirect no matter what page siteone is on I have an account on theirsite.com and I want to be able to submit my login credentials from mysite.com/page1.php and then redirect back to mysite.com/page2.php. I've been Googling for hours now and nothing I can find works and I don't know a thing about cURL and would rather not get into it. Not to mention, I'm using free hosting for now and I don't believe I'm able to use cURL anyways. I can get it to log in with the credentials just fine, that's no problem, but I just have no clue how to get it to redirect back to my page or just send the credentials and then staying on my page because I could work with that as well (send credentials to theirsite.com from mysite.com/page1.php and staying on mysite.com/page1.php). Is there anyone that could give me a hand on how to do this without using cURL since my php.ini is not editable? Thanks Hello: I'm trying to redirect my current site to point to the secure site, and am having a problem getting it to work for all instances. I currently have this: .htaccess Code: [Select] RewriteEngine on RewriteRule ^$ https://www.mysite.com/index.htm This works fine when using the URLs "www.mysite.com" and "http://www.mysite.com" But when I enter "mysite.com" it directs to something like "https://www.mysite.com/www.mysite.com" which is incorrect. Also, if I enter a URL like "http://www.mysite.com/about.htm" it does not direct to "https" What is the trick to always have the "https" no matter what URL is entered? Any help would be great. Thanks! How do I only redirect the page when index.php is present? Not sure if I'm trying to achieve something totally crazy here, or if this is something pretty standard. Didn't have much luck with searching as I'm not fully down with all the terms. (A) I have one site providing an RSS feed. (B) I have one site I want to search, once for each of the items in the feed A. (C) I want the results of the search in (B) to be displayed on page (C). So for example, the feed on (A) says; apples bananas oranges cheese I want site (B) to search for each of those terms (by passing the item in the feed (A) to the ?search= part of the URL of that page) and then show the results from THAT search on page C. Bit of a complex one, let me know if you need me to clarify. Thanks for any help! Hi, I have a, let's call it, Main page, and it refreshes every 5 seconds to check the database... If it finds a result, it kills the refresh function and allows a DIV to call a page into itself via another function on the Main page, which refreshes every second, it's a timer count down clock... The problem is, that if the timer runs down to zero, I have it do a lot of things, but then I need it to either refresh the Main page, redirect the Main page, or close the Main page entirely... Does anyone know how I could perform either 3 of those actions from within the page that's inside of the DIV? Hi,
I am trying to redirect a page to another page based on if the page contains an image with an exact source.
I have this so far:
if ( $("span#bannerhold:has(img[src='http://www.website.com/images/banners/banner1.gif'])")){ location.href = "http://www.google.com" }However it doesn't seem to work. Any ideas why? Thanks! Hai Folks,
Please help me in this situation,
Actually my case is bit complicated
i have a list of few movies.please check the attached file.
If we click on each movies ,i want to direct into next page describing details of that clicked movie (review,image,syopsis,time).can you help me to write code
following is the code for showing movie list.
<?php Hello everyone, I am creating a site that has two modes 1.Default 2.under construction I use database to see weather the site is under construction or not. The template of under construction is different and is stored in a another directory eg: site url: www.my.com under construction page: www.my.com/uc now i want that when the database is selected for under construction the URL should show www.my.com not www.my.com/uc Please help me with this. I tried to redirect with header(location: '.......'); but in the URL it shows www.my.com/uc Thanks. Hello, Please... could someone look at my existing code below at tell me how I can establish a REDIRECT PAGE {header("Location: thankyou.php");} to fit in my code and WITHOUT generating a MySQL error once the php page is processed on the server? I wish to place the HTML CODE at bottom of my page labeled " // THE RESULTS OF THE FORM RENDERED AS PURE HTML " to be on a separate " thanks.php " page. thanks mrjap1 Code: [Select] <?php $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $registration_date = $_POST['registration_date']; // 1. Create a database connection $con = mysql_connect("localhost","mrino_mydata","runns100"); if (!$con) { die('Database connection failed could not connect: ' . mysql_error()); } // 2. Select a database to use $db_select = mysql_select_db("mrino_FULLENTRYDATA",$con); if (!$db_select) { die('Database selection failed could not connect: ' . mysql_error()); } mysql_select_db("mrino_FULLENTRYDATA", $con); // Data Submitted With My Form $sql="INSERT IGNORE INTO `mrino_FULLENTRYDATA`.`backpage1` (`id` , `first_name` , `last_name` , `email` , `registration_date`) VALUES (NULL , '$_POST[first_name]' , '$_POST[last_name]' , '$_POST[email]', NOW( ))"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } // 3. Close Connection mysql_close($con); ?> <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'myemailaddress@gmail.com'; // GATHERING the FORM DATA VARIABLES $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $registration_date = $_POST['registration_date']; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $body = <<<EOD <br /><hr><br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Registration Date:</strong> $date at $time <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML // Remove Header Injections $match = "/(bcc:|cc:|content\-type:)/i"; if (preg_match($match, $from) || preg_match($match, $subject) || preg_match($match, $body)) { die("Header injection detected."); } // Simple filtering on all of our input variables $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); $from = preg_replace("([\r\n])", "", $_POST['email']); $emailSubject = preg_replace("([\r\n])", "", $_POST['$emailSubject']); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> hello, so i have this contact page on my website, but i want people to actually know if the mail got sent or not, so i first have contact.php, which sends all the information to sendmail.php, which in turn tells redirect.php wether or not the mail was sent, and redirect.php then shows this information for the user to see, and has a 10 second timer before users get sent back.. here is the website: http://hcg.drokz.eu.clanservers.com/ all files are in the same folder so here is my code: Code: (sendmail.php) [Select] <?php $url1 = 'redirect.php?sent=sent'; $url2 = 'redirect.php?sent=fail'; $timeout = 0; ?> <?php $to = "admin@hcg.drokz.eu.clanservers.com"; $name = $_REQUEST['name'] ; $subjectm = $_REQUEST['subject'] ; $subject = "contact form entry on the hcg website by $name with the subject $subjectm"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; ?> <?php if($sent) {header('Refresh: ' . $timeout . ';url=' . $url1); ?> <meta http-equiv="refresh" content="<?php echo($timeout) ?>;url=<?php echo($url1); ?>"> <script type="text/javascript"> setTimeout(function(){window.location.replace("<?php echo($url1); ?>";}, <?php echo($timeout * 1000); ?>); </script> <?php } ; ?> <?php else {header('Refresh: ' . $timeout . ';url=' . $url2); ?> <meta http-equiv="refresh" content="<?php echo($timeout) ?>;url=<?php echo($url2); ?>"> <script type="text/javascript"> setTimeout(function(){window.location.replace("<?php echo($url2); ?>";}, <?php echo($timeout * 1000); ?>); </script> <?php } ; ?> <a href='contact.php'> this page should redirect you, if nothing happens, click here! </a> Code: (redirect.php) [Select] <?php $sent = $_GET['sent'] ; ?> <?php $url = 'contact.php'; $timeout = 10; ?> <?php header('Refresh: ' . $timeout . ';url=' . $url); ?> <meta http-equiv="refresh" content="<?php echo($timeout) ?>;url=<?php echo($url); ?>"> <script type="text/javascript"> setTimeout(function(){window.location.replace("<?php echo($url); ?>";}, <?php echo($timeout * 1000); ?>); </script> <h1> <?php if($sent == sent) {echo "Success!" } ; elseif($sent == fail) {echo "Failure!" } ; ?></h1> <?php if($sent == sent) {echo "your email has been sent successfully and we will reply as soon as we can."} ; elseif($sent == fail) {echo "we have encountered a problem while sending your email, please try again!"} ; ?> <p> <a href='contact.php'> this page will redirect you in 10 seconds, if nothing happens or you can't wait, click here! </a> hi we want some code can any one help me what i do? we have traffic on site1.com we want this traffic redirect to another site site2.com i know how to redirected .but when echo $_SERVER["HTTP_REFERER"] in site2.com its show me traffic from google.com not show traffic from site1.com how to code please help me How I am wondering how to add a redirect to a form with multiple buttons. All should redirect to same page |