PHP - Code Works. .htaccess Modifications Work. They Don't Work Together.
This one requires lots of up front information:
I have a page, for this example that I will call page.php. It takes get parameters, and for this example I'll call the parameter "step". So I have a URL like this: page.php?step=1 This page has a form with an action of page.php?step=1. The code on the page validates the posting information. If the information is bad, it returns the user to page.php?step=1; if it is good, it takes the user to page.php?step=2 via header( "location:page.php?step=2" ). So redirection is done by relative path, not full URLs. This all works as expected. Now what I've done is set .htaccess to be HTTPS for this page, via this code: # Turn SSL on for payments RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] This works (initially). However, once you try to post the form, it just redirects back to the step=1 version of the page. I really don't know how or why that would be. I'm not sure how else I can explain this or what other information you may have. But it's frustrating to not get a page working in HTTPS that works in HTTP. Very odd. Any suggestions? (I don't even really know the best location to figure out when/why it's redirecting back to the original page.) Similar TutorialsHello everyone, I'm having this problem which is really annoying, tried to solve it but couldn't, I write that code in PHPMyAdmin and it works great, but it doesn't work in the website it self ok long story short, there are three tables, hotels, cities, countries hotels include in addition to hotel info, 2 columns (city_id) and (country_id) Cities include id and name and also countries include id and name what I was trying to do, that when a person inputs a city or country name in the search form, it should get the hotels that exists in this city or country, but unfortunately it shows all the hotels in all cities and countries, although the pagination code for number of pages works just fine, it count the number of hotels in that city or country and show the number of pages correctly so here is the code for both for hotel search Code: [Select] class hotelManager { public function getHotel($where) { $where = isset($_POST['where']) ? $_POST['where'] : ""; $dbObj = new DB(); $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql); $arr = array(); echo "<table>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\"> <a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink\">".$row['name']."</a> </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> </table>"; echo "</td>"; echo "</tr>"; } echo "</table>"; for hotel pagination Code: [Select] <?php include("includes/hotelsManager.php"); $hotelObj = new hotelManager(); $where = isset($_POST['where']) ? $_POST['where'] : ""; if(isset($_POST['where'])) { $hotelObj -> getHotel($where); $per_page = 9; //Calculating no of pages $sql = "select * from hotels where city_id = (select id from cities where name = '$where' ) or country_id = (select id from countries where name = '$where' )"; $result = MYSQL_QUERY($sql) or die("<br />No Hotels found in this city, please check the city name and try again"); $count = mysql_num_rows($result); $pages = ceil($count/$per_page) ?> <div id="loading" ></div> <div id="maincontent" ></div> <ul id="pagination"> thank you in advance Hi guys, I need a help to find out what is a problem. Some of my code does not work on my local comp and in the same time it works well when I place it on Internet server. First example: Code: [Select] <body> <?php if($_POST['submit_form'] == "Submit") { $varNewTeam = $_POST['Reg_Team']; $varNewCity = $_POST['Reg_City']; $db = mysql_connect('localhost', 'root', '') or die ('no connection with server'); mysql_select_db('db_m ,$db) or die('DB error'); mysql_query ("INSERT INTO reg2012 VALUES ('$varNewTeam','$varNewCity')") or die('insert error'); } ?> <form action="registration_2012_form.php" method="post"> <p>Team: <input type="text" name="Reg_Team" size="20" maxlength="50" value="<?=$varNewTeam;?>" /><br /></p> <p>City: <input type="text" name="Reg_City" size="20" maxlength="50" value="<?=$varNewCity;?>" /><br /></p> <p><input type="Submit" value="Submit" name="submit_form" /></p> </form> </body> On local comp: It gives me message "Undefined index: submit_form". On Net server works well. If I split the code in two files. In the first one I leave the form with "action=FILE2.php" and put my php code in the second file "FILE2.php" - it starts work even on local server. second example: Code: [Select] <body> <?php $db = mysql_connect('localhost', 'root', '') or die ('no connection with server'); mysql_select_db('db_m' ,$db) or die('DB error'); mysql_query ("CREATE TABLE temp1 (team char(50), city char(50) )") or die('create tables error'); ?> </body> It works in the Net and can not create the TABLE on my local comp. I use XAMPP on my local comp (if it's important) I have create a working site at localhost but when I upload it to webhost, it's not working, all link broken.
This is the site.
this is the directory :
The index.php content is :
<?php header('location:home.html'); ?>and the .htaccess content is : RewriteEngine on RewriteRule ^home.html$ main/home.php?main=home [L] RewriteRule ^penyakit.html$ main/home.php?main=penyakit [L] RewriteRule ^review-(.*)\.html$ main/home.php?main=detilgejala&id=$1 [L] RewriteRule ^solusi.html$ main/home.php?main=solusi [L] RewriteRule ^proses$ main/home.php?main=prosessolusi [L] RewriteRule ^bukutamu.html$ main/home.php?main=bukutamu [L] RewriteRule ^send-contact$ main/main_bukutamu/proses_bukutamu.php [L] RewriteRule ^about.html$ main/home.php?main=about [L] RewriteRule ^ensiklopedia.html$ main/home.php?main=ensiklopedia [L] Options All -indexesThis config work in localhost. Thanks for your attention and respond, it help me so much and sorry for the topic's title can't edited it. Edited by havide, 31 October 2014 - 12:35 PM. This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=347820.0 Hello, The following is my situation where I seem to get a 500 error code from the linux server: i have an 'index' file like this: Code: [Select] <?php require("includes/config.php"); $a = $_REQUEST['a']; switch ($a) { case "home": include("frontpage/main.php"); case "user-process": include("user-process.php"); } ?> config.php is something like this: Code: [Select] <?php require(includes/classes/session.class.php); require(includes/classes/user.class.php); require(includes/classes/db.class.php); ... ?> Now if we fall into the case "home" it works fine. Instead, if we fall into user-process it writes to the logs file Fatal Error: Class User does not exist bla bla bla. Why doesn't it exist ? every class is included in the config.php file then index.php includes first config.php ( which has all the classes) and then includes the requested page. I also have a .htaccess file which is as follows: Code: [Select] RewriteEngine On RewriteRule ^([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?/?([^/\.]+)?$ index.php?a=$1&b=$2&c=$3&d=$4&e=$5&f=$6&g=$7 [NC,L] which is used to access in a SEO friendly way the pages that users request.
Hi, this query runs fine when I run it from PHPMyAdmin: UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1 However, when I run the same query in a PHP file on my server, the page doesn't load at all. The message I get is: www.somesite.com is currently unable to handle this request. HTTP ERROR 500. This is my PHP code: <?php include("/database/connection/path/db_connect.php"); $result4 = mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `tran_term_taxonomy` SET `description` = (SELECT keyword from `good_keywords` ORDER BY RAND() LIMIT 1,1) WHERE `tran_term_taxonomy`.`taxonomy` = 'post_tag' AND `tran_term_taxonomy`.`description` = "" LIMIT 1"); echo $result4; ?> So how do I make this query work please? Thanks for your guidance. Hi.., I use below method to export data to excel. header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename=abc.xls'); if I run the script from the server. (http://localhost/export.php) it is work. (pop-up window if i want save or open the file) but if i run the script from the client (http://192.168.1.5/export.php) it is not work. (nothing happen) any idea how to solve this? require_once 'includes/upload.class.php'; $upload = new uploads(); $details = $upload->getFileInformation($id); <?php echo $details['upload_desc']; ?> then here the class. require_once 'db.class.php'; class uploads extends database { private $uploadData; function uploadFile() { public function getFileInformation($id) { $this->uploadData = $this->readData("uploadfiles", "upload_id", $id); return $this->uploadData; } But it wont work! I am trying to work out why the answer to a PHP quiz question is what it is. The code below prints out: b,c,A,B,C, I just can't seem to get my head round how it works, would anyone be able to talk me through it quickly? Code: Code: [Select] <?php class Magic { public $a = "A"; protected $b = array("a" => "A", "b" => "B", "c" => "C"); protected $c = array (1,2,3); public function __get($V) { echo "$V,"; return $this->b[$V]; } public function __set($var, $val) { echo "$var: $val,"; echo $this->$var = $val; } } $m = new Magic(); echo $m->a . "," . $m->b . "," . $m->c . ","; ?> Hi, I'm creating a chat-box application and I'm trying to add IP bans, where the php code checks if the user is banned or not and then insert the chat, but even if the IP address is banned it will still insert the chat. Code: [Select] $ipsql = mysql_query("SELECT * FROM bans WHERE ip='$user_ip'" or die (mysql_error())); $bancheck = mysql_num_rows($ipsql); if($bancheck <= 0){ $sql = mysql_query("INSERT INTO chats (user_ip, user_name, chat_body, date_time) VALUES('$user_ip','$user_name','$chat_body',now())") or die (mysql_error()); } Thanks, Soccerjunki I have the following code is a included file on my main page Code: [Select] class usersOnline { var $timeout = 600; var $count = 0; var $error; var $i = 0; function usersOnline () { $this->timestamp = time(); $this->ip = $this->ipCheck(); $this->new_user(); $this->delete_user(); $this->count_users(); $this->browser = $this->useragentbrowser(); $this->os = $this->useragentos(); } // start user function useragentbrowser(){ $agent = getenv('HTTP_USER_AGENT'); $browserArray = array( 'Windows Mobile' => 'IEMobile', 'Android Mobile' => 'Android', 'iPhone Mobile' => 'iPhone', 'Firefox' => 'Firefox', 'Google Chrome' => 'Chrome', 'Internet Explorer' => 'MSIE', 'Opera' => 'Opera', 'Safari' => 'Safari' ); foreach ($browserArray as $k => $v) { if (preg_match("/$v/", $agent)) { break; } else { $k = "Browser Unknown"; } } $browser = $k; return $browser; } function useragentos(){ $agent = getenv('HTTP_USER_AGENT'); $osArray = array( 'Windows 98' => '(Win98)|(Windows 98)', 'Windows 2000' => '(Windows 2000)|(Windows NT 5.0)', 'Windows ME' => 'Windows ME', 'Windows XP' => '(Windows XP)|(Windows NT 5.1)', 'Windows Vista' => 'Windows NT 6.0', 'Windows 7' => '(Windows NT 6.1)|(Windows NT 7.0)', 'Windows NT 4.0' => '(WinNT)|(Windows NT 4.0)|(WinNT4.0)|(Windows NT)', 'Linux' => '(X11)|(Linux)', 'Mac OS' => '(Mac_PowerPC)|(Macintosh)|(Mac OS)' ); foreach ($osArray as $k => $v) { if (preg_match("/$v/", $agent)) { break; } else { $k = "Unknown OS"; } } $os = $k; return $os; } // end user function ipCheck() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } function new_user() { $insert = mysql_query ("INSERT INTO ******(timestamp, ip, browser, os) VALUES ('$this->timestamp', '$this->ip', '$this->browser', '$this->os')"); if (!$insert) { $this->error[$this->i] = "Unable to record new visitor\r\n"; $this->i ++; } } function delete_user() { $delete = mysql_query ("DELETE FROM ***** WHERE timestamp < ($this->timestamp - $this->timeout)"); if (!$delete) { $this->error[$this->i] = "Unable to delete visitors"; $this->i ++; } } function count_users() { if (count($this->error) == 0) { $count = mysql_num_rows ( mysql_query("SELECT DISTINCT ip FROM *******")); return $count; } } } The problem I have is that $browser and $os are not being inserted into the db, but everything else is. Can anyone help? Thanks James I have this code that changes an image on the hour, of a random hour and stays changed for 2 minutes, regardless of refreshes etc etc, and it has to be the exact same hour and 2 minutes for everyone. I know at the minute it is going to change at 4pm, it is only for testing purposes, I am doind the random time bit later. <?php $minute = date(i); $hour = 16; if ($hour == date(H) && $minute < 3) $buttonimage = "buttonon.png"; else $buttonimage = "buttonoff.png"; ?> <table width="200" border="1"> <tr> <td><img src="<?php echo($buttonimage); ?>" /></td> </tr> </table> Guys i wrote one pinging script but i don't know it works or not... Someone help me about it works or not? <?php site1("http://site.com/sitemap.xml"); site2("http://site2.com/sitemap.xml"); function site1($url){ @file_get_contents("http://www.google.com/webmasters/tools/ping?sitemap=" . $url); @file_get_contents("http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=" . $url); @file_get_contents("http://www.bing.com/webmaster/ping.aspx?siteMap=" . $url); @file_get_contents("http://submissions.ask.com/ping?sitemap=" . $url); } Print "Pinging1 success"; function site2($url){ @file_get_contents("http://www.google.com/webmasters/tools/ping?sitemap=" . $url); @file_get_contents("http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=" . $url); @file_get_contents("http://www.bing.com/webmaster/ping.aspx?siteMap=" . $url); @file_get_contents("http://submissions.ask.com/ping?sitemap=" . $url); } Print "<br>Pinging2 success"; ?> Hello; I'm new to php and to programming in general, but i want to do a little app to help a process on my work, you know, just being pro-active (hoping it doesnt come and byte me in the a** in the future, you know.. "you did it now our life depend on it and you fix it right now!!). So.. I have this really simple piece of code, but its not working and i cant figure out why. I'm trying to use echo to print a couple of link but when i put in the second line everything messes up. the code is: (note the "test lines" i just added them to try to understand what is doing) <?php $client = $_GET['client']; echo "Client " . $client . "<br />"; echo "test line 1"; echo "<a href=\"link1.php?client=".$client.">Link 1</a><br>"; echo "test line 2"; echo "test line 3"; echo "<a href=\"link2.php?client=".$client.">Link 2</a><br>"; ?> When i open the page on firefox i get: === Client myclient test line 1Link 2 === Where the link (underlined) text is "Link 2" but the it points to something totally different (a mix of the rest of the code). If I remove the second link, like he <?php $client = $_GET['client']; echo "Client " . $client . "<br />"; echo "test line 1"; echo "<a href=\"link1.php?client=".$client.">Link 1</a><br>"; echo "test line 2"; echo "test line 3"; ?> I get what i'd expect: === Client myclient test line 1Link 1 test line 2test line 3 === Im totally lost, im not sure if its a browser issue, a server issue or just the code My setup: WAMP 2.1 (Apache) I'm opening the "site" with Firefox 3.6.15 and IE6, both show the same result Windows XP (dont know if it matters) The file is saved as php tried changing "echo" with "print", same result Umm.. thats it... Please let me know if you need any more info Thanks everyone edit: typo on subject edit: yet another typo Hi, I am having difficulties with the login section on a website. I have tried to update the old funtion names which have been deprecated, but when I do this the login will not work. This is the log.php file, (this is required by index.php on the restricted directory to access the page). Code: [Select] <?php session_start(); ?> <?php $hostname = ".."; $username = ".."; $password = ".."; $database = ".."; $link = MYSQL_CONNECT($hostname,$username,$password); mysql_select_db($database); ?> <?php if($_GET['action'] == "login") { $conn = mysql_connect("..","..","..); $db = mysql_select_db(".."); //Your database name goes in this field. $name = $_POST['user']; $ip=$_SERVER['REMOTE_ADDR']; $var = mysql_real_escape_string($var); $country = file_get_contents('http://stonito.com/script/geoip/?ip='.$ip); $q_user = mysql_query("SELECT * FROM customer WHERE username='$name'"); ?> <?php $insert_query = ("INSERT INTO login(username, ip, country) VALUES ('$name','$ip','$country');"); mysql_query($insert_query) or die('Error, insert query failed'); ?> <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { session_register("name"); header("Location: ../index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: .."); exit; } } else { header("Location: .."); exit; } } // if the session is not registered if(session_is_registered("name") == false) { header("Location: login.php"); } ?> The two old code parts. causing the problems are session_register("name"); session_is_registered . When I change update elements in the code block shown below, it will not work. Can anyone tell me why please? Code: [Select] <?php if(mysql_num_rows($q_user) == 1) { $query = mysql_query("SELECT * FROM customer WHERE username='$name'"); $data = mysql_fetch_array($query); if($_POST['pwd'] == $data['password']) { $_SESSION['name']; header("Location: ../download/index.php?un=$name"); // This is the page that you want to open if the user successfully logs in to your website. exit; } else { header("Location: .."); exit; } } else { header("Location: .."); exit; } } if(!isset($_SESSION['name'])) { header("Location: http://www.myurl.com"); } Any help would be very gratefully received. I have this little code that I cannot get to work Code: [Select] $sql_buildings = ("SELECT castle, treasury, huts, [b]leader_id[/b] FROM teams WHERE team_id=[b]".$_GET['t']." [/b]"); $rsbuildings = mysql_query($sql_buildings); if($rsbuildings[".$_GET['t']."] == 'leader_id' ){ The problem is this part: Code: [Select] if($rsbuildings[[b]".$_GET['t']."[/b]] == '[b]leader_id[/b]' ){ How can I write it to have these to values work? Hello I am getting the following error when accessing this page... test.php Code: [Select] <?php $url = "http://www.howtogeek.com"; $str = file_get_contents($url); function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } ?> Easy right??? I am getting the following error. Code: [Select] Parse error: syntax error, unexpected ':' in /home/username/public_html/tools/crawler/test.php on line 2 The above example code was taken from How To Geek. http://www.howtogeek.com/howto/programming/php-get-the-contents-of-a-web-page-rss-feed-or-xml-file-into-a-string-variable/ I have tried single quotes, removed the http:// part, a few other small things but I just don't understand. Can anyone shed some light on it? Thanks! Hi everybody! I'm creating a site and none of my php-code works. I tried to do a simple php-code to test it but it doesn't work either. The simple php-code: <?php echo "hello"; ?> Code: [Select] <?php require "global.php"; if ($_POST) { $name = $_POST['name']; $data = sprintf("INSERT INTO forums VALUES (DEFAULT,'$name')"); mysql_query($data); $fid = mysql_insert_id(); header( 'Location: viewforum.php?fid='.$fid); exit; } echo ' <form action="" method="POST"> <table> <tr><td>Forum Name: </td><td><input name="name" /></td></tr> </table> <input type="submit" value=" Add Forum " /> </form>'; ?> This added forums whenever I made one to my MySQL database in the table "forums" For whatever reason, whenever I make a forum, it makes it end in ".php?fid=0" and does not create the forum on the database. Any ideas? Thanks! |