PHP - Setting The Domain Correctly For Cookies
I have a script where $site (location of where it's hosted) will either be in the format of a subdomain e.g. 'something.domain.com' or a domain 'domain.com', and the cookies are handled like the following:
ini_set('session.cookie_domain', $site); //for sessions setcookie($name, $value, $expiry, '/', $site, false, true); //for othersMy question is the script's canonical url is non-www and I don't want other subdomains for various reasons (including security) being able to access/read the cookies (e.g. 'www.something.domain.com' or 'www.domain.com' or 'somethingelse.domain.com' or 'www.somethingelse.domain.com'), so would you say the above will work okay (providing $site does not proceed with www. or .)? I have searched around (also referred to php.net) and believe the above will be okay from my understanding - but wanted reassurance as I had read many conflicting/confusing information! Edit: If the above won't work - I thought about maybe setting $site to false (the .htaccess code would enforce access only via non-www)? Edited by newbtophp, 25 January 2015 - 05:03 PM. Similar TutorialsWell this isn't all about cookies or maybe it is, I'm not to sure. On top of this my script has suddenly broke and stops at check.php I'm also not sure how I should go about checking the cookie to identify the user and how to keep other from viewing the output page(s). Code: (index.html) [Select] <html> <head> <title>Deadnode.com</title> <style type="text/css"> img { position:absolute; left:300px; top:130px; z-index:-1; } form { position:absolute; left:365px; top:248px; z-index:0; } </style> </head> <body> <img src="iL0bw.png" /> <form method="post" action="check.php"> <center><table> <tr><td><font face="verdana,arial" size=-1>Username:</td><td><input type="text" size="25" name="user"></td> <tr><td><font face="verdana,arial" size=-1>Password:</td><td><input type="password" size="25" name="pwd"></td> <tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Login"></td></tr> </table></center> </form> </body> </html> Code: (function.php) [Select] <?php function check() { $admin="test"; $pass="test"; if (isset($_POST["user"]) && $_POST["user"] == $admin && isset($_POST["pwd"]) && $_POST["pwd"] == $pass) { header('Location: output.php'); setcookie("usr", "test", time()+3600); else { header('Location: index.html'); } } ?> Code: (check.php) [Select] <?php require('function.php'); check(); ?> Code: (output.php) [Select] <?php require('check.php'); ?> <html> <body> <p>Congrats!</p> </body> </html> Hello, It's as subject says. Here is the code: <? //Config include_once "../../config/config.php"; //Variables $username = $_POST["username"]; $username = mysql_real_escape_string($username); $password = $_POST["password"]; $password = md5($password); //Check for User $query = "SELECT * FROM users WHERE username='$username' AND password='$password'"; $query = mysql_query($query); //If user not found if(mysql_num_rows($query)!="1") { echo "No User Found"; } //If User Found else { while($row=mysql_fetch_array($query)) { $fname = $row["fname"]; $lname = $row["lname"]; $userid = $row["id"]; $admin = $row["admin"]; } setcookie("fname", "$fname"); setcookie("lname", "$lname"); setcookie("userid", "$userid"); setcookie("admin", "$admin"); header('Location: ../../../portal/index.php'); } ?> On the page it forwards to, I write print_r($_COOKIE); Yet it doesn't show my newly set cookies, yet the above snipped does on the script code above. George 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. 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 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 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! 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"> 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"; } ?> 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 This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=359139.0 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 want to get all the domain name on the internet and put them into a database. is there a way to get this. 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"? What I'm trying to do is get my $_SESSION to work throughout my website.
I'm quite new to PHP, so the PHP Manual didn't make much sense to me, so I thought I'd post here! ^^
I've got my login script under /session/ and I want it to be able to display your username on the homepage (/), but it only works inside /session/.
If you are wondering, I am using PHP-Login Advanced.
Thank you,
- Connor!
Edited by ConnorMcF, 26 January 2015 - 04:45 PM. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=353448.0 HI,
I am triying to check a domain is valid or not using PHP. If the domian is not a valid one the name shoud be empty string.
So I tried using preg_match() and preg_replace(). But I couldn't get it to work.
This is my code sofar -
if (preg_match ('/^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$/', $domain)) { $mydomain = $domain; } else { $mydomain = preg_replace("/^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$/", "", $domain); }When I am tring using valid and invalid domain name its always going to else part. Eg: example.com example.t.t.c Hope somebody may help me out. Thank you. $msg = "testing message"; $to = "$email"; $subjects = "testing"; $mailheaders = "From : singapore \n"; mail($to, $subjects, $msg, $mailheaders); Received in the email From : server name Question is I need it to receive as my domain name (FROM). Not the server name (FROM). |