Jump to content

imgrooot

Members
  • Posts

    383
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by imgrooot

  1. Yes this is what I was looking for. I'll give it a shot. Thanks you.
  2. Suere thing. Here is my code setup for sending emails. $from_name = 'MyWebsite'; $from_email = 'info@mywebsite.com'; $user_email = 'user@email.com'; $post_subject = 'Hello World'; $post_message = 'It was a dark and stormy night...'; // Multiple recipients $send_to = $user_email; // Subject $subject = $post_subject; // Message $message = " <html> <body> <p>{$post_message}</p> </body> </html> "; // To send HTML mail, the Content-type header must be set $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-type: text/html; charset=iso-8859-1'; // Additional headers $headers[] = 'From: '.$from_name.' <'.$from_email.'>'; // Mail it mail($send_to, $subject, $message, implode("\r\n", $headers));
  3. Say I am running multiple contests at the same time. Each contest may have a different end date. One contest might run for a day, while the other one might run for 5 days. Below is the code done my way. I was wondering how you can improve it to make it more efficient? $current_date = date('Y-m-d H:i:s'); $find_contest = $db->prepare("SELECT days_count, date_started FROM contests WHERE status = :status"); $find_contest->bindValue(':status', 1); $find_contest->execute(); $result_contest = $find_contest->fetchAll(PDO::FETCH_ASSOC); if(count($result_contest) > 0) { foreach($result_contest as $row) { $days_count = $row['days_count']; // NUMBER OF DAYS THE CONTEST IS RUNNING $date_started = $row['date_started']; // START DATE FOR THE CONTEST $date_1 = DateTime::createFromFormat('Y-m-d H:i:s',$date_started); $date_1->modify('+1 day'); $end_date_1 = $date_1->format('Y-m-d H:i:s'); $date_2 = DateTime::createFromFormat('Y-m-d H:i:s',$date_started); $date_2->modify('+2 days'); $end_date_2 = $date_2->format('Y-m-d H:i:s'); $date_3 = DateTime::createFromFormat('Y-m-d H:i:s',$date_started); $date_3->modify('+3 days'); $end_date_3 = $date_3->format('Y-m-d H:i:s'); if($days_count == 1) { if($current_date > $end_date_1 AND $current_date < $end_date_2) { $day = 1; $end_date = $end_date_1; require 'run-contest.php'; } } else if($days_count == 2) { if($current_date > $end_date_1 AND $current_date < $end_date_2) { $day = 1; $end_date = $end_date_1; require 'run-contest.php'; } else if($current_date > $end_date_2 AND $current_date < $end_date_3) { $day = 2; $end_date = $end_date_2; require 'run-contest.php'; } else {} } else {} } }
  4. Say I have two variables like below. I basically want to select one of them, but through random choice. How do I do that? $orange = 'Orange'; $apple = 'Apple';
  5. Say I have an email info@website.com created in cPanel on a web hosting company. I want to send email notifications to users on my website. I am using PHP Mailer to send the emails. But all the emails go directly into their junk box/spam folder, unless they confirm that info@website.com is not junk. I am wondering if there is a work around for this?
  6. Here's how I would do it. // GET THE DATE FROM YOUR DATABASE TABLE $db_date = '12-08-2018'; // SUBTRACT DAYS FROM IT $get_date = DateTime::createFromFormat('Y-m-d H:i:s',$db_date); $get_date->modify('-30 days'); $new_date = $get_date->format('Y-m-d H:i:s'); // NEW DATE WILL BE YOUR ORIGINAL DATE MINUS 30 DAYS echo $new_date;
  7. Well one of the things the person mentioned was that SERVER['DOCUMENT_ROOT'] doesn't work on all servers and that DIR is better for PHP >= 5.3.
  8. Got it. And I actually read that on Stackoverflow.
  9. Could you please explain how using "$_SERVER['PHP_SELF']" makes it XSS vulnerable? What do I use it in it's place instead?
  10. I've read that not to use $_SERVER['DOCUMENT_ROOT'] Instead use define('PROJECT_ROOT', dirname(dirname(__FILE__))); $project_root = PROJECT_ROOT; So using that, it would look like this. require_once $project_root . '/core/init.php'; require_once $project_root . '/members/dashboard.php'; It seems to work fine now.
  11. Ah yes that's exactly what I was looking for. I have a couple questions. 1. <?=APP_PREFIX?>. Is this the same as "<?php =APP_PREFIX ?>" ? 2. What is the reason for the = sign in =APP_PREFIX? 3. I want to include it in the include/require files like this. require_once '../core/init.php'; require_once '/members/dashboard.php'; How do I properly add the APP_PREFIX to the require_once above? I've tried different ways and i still get an error like this. define('APP_PREFIX', '/mysite'); $root_dir = APP_PREFIX; require_once "$root_dir/core/init.php"; Warning: require_once(/mysite/core/init.php): failed to open stream: No such file or directory Fatal error: require_once(): Failed opening required '/mysite/core/init.php' (include_path='C:\xampp\php\PEAR')
  12. I get what you're saying but your method of leading slash doesn't work. For e.g. // CURRENT PAGE LOCATION: mysite/members/dashboard.php // YOUR METHOD <a href="/index">LINK</a> // RESULT localhost/index // WHAT I WANT IS localhost/mysite/index // I CAN ONLY GET THAT IF THE URL IS LIKE THIS <a href="../index">LINK</a> Maybe I'm just not getting your leading slash. Please do explain what I am doing wrong.
  13. Here is my setup for the absolute URL. The normal a links seem to work fine and so are the includes/requires. But the scripts in the HEAD section of the site don't seem to load, even though the path is correct. define('PROJECT_ROOT', dirname(dirname(__FILE__))); $root_dir = PROJECT_ROOT; // THIS WOULD GET ME THE ROOT DIRECTORY OF MY SITE C:\xampp\htdocs\mysite // IF I INCLUDE IT IN THESE FILES <link href="<?php echo $root_dir; ?>/css/screen.css" media="screen" rel="stylesheet" /> <script src="<?php echo $root_dir; ?>/javascripts/jquery.js"></script> // I GET THIS ERROR IN THE INSPECT ELEMENTS WINDOW Not allowed to load local resource: file:///C:/xampp/htdocs/mysite/css/screen.css Not allowed to load local resource: file:///C:/xampp/htdocs/mysite/javascripts/jquery.js // IF USE RIGHT CLICK AND SEE THE PAGE SOURCE, THE PROJECT ROOT SLASHES ARE BACKWARDS LIKE THIS <link href="C:\xampp\htdocs\mysite/css/screen.css" media="screen" rel="stylesheet" /> <script src="C:\xampp\htdocs\mysite/javascripts/jquery.js"></script> So what do you think is going on?
  14. I'm sorry but your post does not show how to get an absolute URL. I did some digging and found one of the posts here. https://stackoverflow.com/questions/6511496/how-to-generate-absolute-url-path-to-a-script-file I will try the absolute URLs based on their examples.
  15. Say I have two areas of a website. 1 - root directory (index, sign up, sign in) 2 - folders (this would contain folders such as snippets, members, assets) Due to the nature of the folders, the links cannot be the same as they are on the pages in the root directory. Index page for example. So if I'm on members/dashboard.php, any a links linking to index.php, will have to have "../" in front of them. To solve the issue, my current set up is like this. But I understand it's not the most efficient way to do this. I was wondering if you can share your expertise for a better method. $currentPage = basename($_SERVER['PHP_SELF'], ".php"); <?php if($currentPage == 'index' || $currentPage == 'members') { ?> <!DOCTYPE HTML> <head> <meta charset="UTF-8"> <title></title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content=""> <link rel="shortcut icon" href="images/favicon.ico.png"> <link href="css/screen.css" media="screen" rel="stylesheet" /> </head> <body> <a href="index"> <img src="images/logo.PNG" alt="logo" /> </a> </body> <?php } else { ?> <!DOCTYPE HTML> <head> <meta charset="UTF-8"> <title></title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content=""> <link rel="shortcut icon" href="../images/favicon.ico.png"> <link href="../css/screen.css" media="screen" rel="stylesheet" /> </head> <body> <a href="../index"> <img src="../images/logo.PNG" alt="logo" /> </a> </body> <?php } else { ?>
  16. So in your opinion, which method is better to use? The $_COOKIE method I used above or a $_SESSION one?
  17. Because if I'm not mistaken, the SESSION only lasts until you close the browser. I want to use the COOKIES so that the referral name is saved for up to a year, unless someone deletes their browser cookies or uses a different referral link.
  18. Of course it was that simple. I should have thought of that. It works like a charm now. Thanks again.
  19. Not sure if I understand you correctly. But I have found a fix around. Instead of having the referral link go directly to the sign up page, I instead link it to the home page. Like this "www.mysite.com/?ref=johnsmith". This way when the user goes to the sign up page, the cookie will already be set. I tried it and it seems to work fine.
  20. I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
  21. I guess I really needed that sleep. I have found the solution. Apparently I didn't know how EasyApache 4 really worked. I had the package installed that contained the GMP extension. But The extension was not enabled. Once it was enabled, the package provision had to be reinstalled. That was it. Now it works.
  22. This is going to seem like a long shot. I've been trying to figure this out all night and still no luck. Perhaps someone more experienced can tell me why it's not working. I have a CloudNX server with fasthosts.co.uk. I have installed a GMP extension on the WHM panel using EasyApache 4. Now I even tried adding "extension=gmp.so" in the php.ini file of both WHM and the cPanel where the website is located. But no matter what, my site gives me an error like this. Fatal error: Uncaught exception 'Exception' with message 'GMP extension seems not to be installed' in I am using this API https://block.io/api/simple/php . It requires GMP extension. It works great on my local server. I have no issue with GMP extension there. So does anyone have a clue as to what I might be doing wrong and how I can fix this?
  23. Oh wow, that's a much more efficient way of doing it. My original query has more fields so i tried to simplify it for demonstration purposes. That's where I made the mistake of having :user_id when there shouldn't be. Just one question. Your example shows inserting two fields(id, name). If I wanted to insert four fields, would it look like this? $params[] = '(?,?,?,?)'; array_push($data, $id, $name, $field3, $field4);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.