PHP - Access Cookie Of Parent Domain
I expected the following script to display a single cookie on the main page (cookie_2, and both the main page cookie and the subdomain cookie (cookie_3) within the iframe.
In actuality, the main page was as expected, but the iframe only displays cookie_3.
Can anyone explain what I am witnessing, and why the subdomain wouldn't be able to access the cookie set in the parent?
<?php setcookie("cookie_".count(explode('.', $_SERVER['HTTP_HOST'])), 'Hello from '.$_SERVER['HTTP_HOST']); echo('<pre>'.print_r($_COOKIE,1).'</pre>'); ?> <iframe src="http://test.mysite.com/testing/cookietest.php"></iframe> Similar TutorialsTrying to sort out setting a cookie that allows visitor to decide which sub domain to go directly to in subsequent visits. Somewhat complicated by the fact that the sub domains are running seprate instances of wordpress. Here's the code... any suggestions appreciated! Code: [Select] <?php if (isset($_POST['submitted'])) { $site=$_POST['site']; setcookie("SitePref",$site, time() + 60*60*24*30, 'historybee.com'); if ($site == 'ms') { header("Location: http://ms.historybee.com/"); } elseif ($site == 'hs') { define('WP_USE_THEMES', true); require('./wp-blog-header.php'); } } else { //if we have a cookie, load the site if (isset($_COOKIE['SitePref'])) { if (($_COOKIE['SitePref']) == 'hs') { define('WP_USE_THEMES', true); require('./wp-blog-header.php'); } else { header("Location: http://ms.historybee.com/"); } } else { //if we don't have a cookie, load the form ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>The National History Bee</title> </head> <body style="margin:0;padding:0;background: url('http://ms.historybee.com/wp-content/themes/makinghistoryblue/img/body_bg_hb5.jpg') repeat-x scroll center top #F2BF3B;"> <div align="center" style="width:800px;margin:0 auto;background:#fff;"> <p><img src="http://ms.historybee.com/wp-content/themes/makinghistoryblue/img/nhb_logo.png"> <p><h1>Welcome to the National History Bee!</h1> <p>The National History Bee has both High School and Middle School competitions. <p>Please choose which site you would like to visit. Your choice will be remembered for 30 days. <form action= "<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST"> <input type="radio" name="site" value="ms"> Middle School Competition <input type="radio" name="site" value="hs"> High School Competition <input type ="hidden" name="submitted" value="true"> <p><input type="submit" value="Remember My Choice"> </form> <br /><br /><br /> </div> </body> </html> <?php } } ?> RewriteCond %{HTTP_HOST} !^www.example.com.au$ [NC] RewriteCond %{HTTP_HOST} !^https://www.example.com.au$ [NC] RewriteRule ^(.*)$ http://www.example.com.au/$1 [R,L]Hi All I have my website 90% working on https, fully working on http and I have managed to redirect from none www to www What I am looking to do it if the user happens to enter https then make them go to my www version I have manage to get them to go to my www version if they do not put in www but I am lost in how to redirect them from https to http here is what I have so far and I just cannot figure it out thanks Alan I tried many ways but unable to pass sessions to virtual subdomains on my site.. I edited ihi.ini file and included Code: [Select] session.cookie_domain = .mydomain.com I like to add that session is active on my main domain for www.mydomain.com only.. So how do I pass sessions for WWW to other subdomains ? Thanks n Advance Okay so I am trying to add api functionality to my website so people can develop apps for it and what not. Well there is one problem I came across.. when you want to retrieve the user currently logged in information you need the php session cookie value and then set the session id. But.. sense this application is offsite then the session cookie is not in the header because the session cookie is set on my website, not the app developers. How can I get the users information that is logged in offsite? I have a user class that is very dependent on the database class, which is why the user class extends the database. I tried creating a protected method in the parent class called getDBCObject, which returned the database object/variable/handle that I want the user to have access to. I tried the method below, but it doesn't work: <?php /* * @DATABASE * ~~~~~~~~~~~~ * @FILE DESCRIPTION: Handles all database related processes * @LAST MODIFIED: April 4, 2012 */ class database { protected $dbc; function __construct($db_host, $db_name, $db_user, $db_password) { try { $this->dbc = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_password); } catch(PDOException $e) { echo '<b>An error occured while trying to create a database connection: </b>'. $e->getMessage(); } } /* * @METHOD getDBCObject * @DESC Gives the $dbc object/variable to its child classes */ protected function getDBCObject() { return $this->dbc; } } ?> My user class: <?php /* * @DATABASE * ~~~~~~~~~~~~ * @FILE DESCRIPTION: User related proccess * @LAST MODIFIED: April 5, 2012 */ class user extends database { protected $dbc; public function __construct() { if(parent::getDBCObject() == null) { echo '<br/>A database class/connection is required before creating the user class.'; } } public function isLoggedIn() { if($_COOKIE['user']) { //soon to come } else { return false; } } } ?> Any feedback on how I can let the user class use the $dbc variable in the database class? I have these two classes: Code: [Select] <?php class A { private $id; public function __construct() { $this->id = '11111'; } public function getProperty($prop) { return $this->$prop; } }?> Code: [Select] <?php class B extends A { private $message = "Nope, can't see it"; public function __construct() { parent::__construct(); $this->message = "Yep, I can see it"; } }?> I tried this, but it just outputs the id (the first call) Code: [Select] $class = new B; echo $class->getProperty('id'); echo $class->getProperty('message'); Why is that? I thought I could use a parent method on a child property.. *EDIT* Using a public or protected visibility on the message property gets me the output I expect...how come? This topic has been moved to the corner of 3rd Avenue and mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359430.0 I have two domains both running SSL. Let's call them old-domain and new-domain. old-domain is permanently redirecting traffic to new-domain. There are still a lot of links out there to old-domain with https://. If I were to remove SSL from old-domain but keep SSL on new-domain, I am betting that users will be getting some sort of certificate error. Right? Any way around that if I want to remove SSL from old-domain?
I was wondering if anyone knew of a good way to query domain name availability with php? I know how to get an ip adress from a domain by using gethostbyname(), but I wanted to know if it was possible to get the domain name from the ip address. As in a website address (example.com) has a ip address of xxx.xx.xxx.xxx What I am trying to do is to get the 'example.com' domain name from the ip address. Is this at all possible, if so, how can it be done? Thanks in advance for any that helps out. I'm sorry if this is in the wrong section. I'm working on coding a page that will pull data from a servlet that's already been coded. Right now I'm just trying to get it to pull and display any information. The developer who coded the servlet says it works on his server and I'd rather not badger him with questions. Any help you can provide would be greatly appreciated. So I am running Wampserver 2.5 a basic installation as I have not changed any settings and my HTML page is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> I have a website on wordpress, at first it was on a friends server, but he switched it so its on bluehost. The website URL is an IP address with a slash and a name. However, I registered a domain name at godaddy. I was able to change the nameservers so that the URL of the index page of my website was changed to the domain name, however, when I click onto any other page from that page, it goes back to the IP address URL. What can I do? Thanks. Hello I am curious if it is even possible to get the domain when using iframes/frames? eg. domain2 shows a file from domain1 in an iframe. Can domain1 grab domain name "domian2"? This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=359139.0 Hello everyone, I have a site where the folders are set up in this arrangement: Code: [Select] _ ClientsFolder - client1 - | page-folder - pages are here (index.php) | | image-folder - images here | |_include-folder - style.css and database connections here _ client2 - | page-folder - pages are here (index.php) | | image-folder - images here | |_include-folder - style.css and database connections here PageIncludeFolder - include pages here (index.inc.php) The reason my folders are set up this way is because multiple clients will be using my site, but each client will have a customized sub-domain, yet all the code on the pages will be the same. All of the pages for the clients site are placed in ClientsFolder/client1/page-folder. Each page in this folder is a page that simply includes an entire page from the PageIncludeFolder. For example: ClientsFolder/client1/page-folder/index.php and ClientsFolder/client2/page-folder/index.php are exactly the same, file, which simply has the following code: Code: [Select] <?php include("../../../PageIncludeFolder/index.inc.php"); ?>The reason for this is so that I can easily modify all the client sites by only modifying the files that are in the PageIncludeFolder. (Trying to work smarter, not harder!) The images, style.css, and script.js files are called from the index.inc.php, which is included on the index.php page. For example, style.css is located at ClientsFolder/client1/page-folder/include-folder/style.css. So to link to the .css file, I have the following code in the index.inc.php file: Code: [Select] <link href="../include-folder/style.css" rel="sytlesheet" type="text/css" /> And images are linked using code similar to this: Code: [Select] <img src="../image-folder/image.jpg" /> Now, when I visit the index.php page by entering the entire url (http://www.mysite.com/ClientsFolder/client1/page-folder/index.php) everything works perfectly. However, as I stated, each client is being set up with a sub-domain. Client 1 has the sub-domain of http://client1/mysite.com, which is pointed to http://www.mysite.com/ClientsFolder/client1/page-folder/index.php. When I try to visit client 1's site using the sub-domain, the index.inc.php page is included perfectly, but the images and the style.css files are not being linked. I know this is kind of confusing, but as you can probably tell, I have spent many, many hours putting this together and now I need help to figure out what is wrong and why certain files are not linking properly ONLY when the page is visited using the sub-domain. ANY help or suggestions are GREATLY appreciated! Thanks everyone! hey guys im making a script where the user gets redirected...but im wanting to make sure the redirection is within the same domain and not being shipped off to another site when using ($_SERVER['HTTP_REFERER'])
now what im using seems to do the trick but im wondering if there is a better method of doing this?...i dont want to use regex either
thank you guys
<?php $match = strpos("http://127.0.0.1/login", $_SERVER['SERVER_NAME']); if ($match && $match > 0 || $match === 0) { echo "domain match"; } ?> Hi, I am trying to see if the domain name in the string is in an array. eg; Code: [Select] mystring='http://google.com/somethingelse'; myarray[]='google.com'; myarray[]='anotherdomain.com'; in this case return TRUE Code: [Select] mystring='http://phpfreaks.com/adir'; myarray[]='google.com'; myarray[]='anotherdomain.com'; in this case return FALSE How would I do this? Thanks, -mme I have two questions: 1. Is it the best way to get the domain of a url by parse_url? or preg_match or str_replace can be better alternatives? 2. What is the best way to remove www from the domains? Note that the domain name itself may contain www too (like www.1www.com) Thank for your attention Hi I have written a server session on login in the main domain and am trying to read it when they are sent to their sub domain. Unfortunately it won't read the session. I have searched for a solution, which points to altering the php ini. Is there another option that anyone knows about. Thanks i want to get all the domain name on the internet and put them into a database. is there a way to get this. |