-
Posts
6,060 -
Joined
-
Last visited
-
Days Won
153
Everything posted by gizmola
-
Being able to pass extra/unlabeled parameters was a feature you could make use of using func_get_args. PHP version 5.6 added variable parameter lists(variadic) and the "..." operator to formalize this and make it easier to use. So now you can have code like this: function giftBasket($occasion, ...$contents) { echo "You purchased the $occasion basket that contains " . implode(', ', $contents) . '.' . PHP_EOL; } giftBasket('Holiday', 'Salmon', 'Crackers', 'Candy'); giftBasket('Birthday', 'Balloons', 'Cupcakes'); giftBasket('Valentine', 'Chocolates'); The "..." operator is called the Spread operator or spread syntax in javascript. Some languages like Ruby call it the "splat" operator, although most use the asterisk. It works to essentially explode an array into individual variables that can then be passed as parameters. function bio($name, $city, $state) { echo "$name is from $city, $state" . PHP_EOL; } $players[] = array('Bob', 'Phoenix', 'AZ'); $players[] = array('Samantha', 'Boise', 'ID'); $players[] = array('Charlie', 'New Haven', 'CT'); foreach ($players as $player) { bio(...$player); } The PHP group has been pretty busy adding features like this to the language.
-
Hope your recuperation goes well. We'll be here when you are feeling better.
-
Not sure what you mean by "not getting"? One thing that's important to understand is that url's involve "web space", not filesystem space on a workstation. If you use FILE|OPEN with your browser, the browser goes into a local mode where it will parse html etc, and will work with local files and paths but rarely do I see this use case. Since I'm not sure what the purpose of your current scripts are, it's hard to say, but a URL is not a filesystem path. Is this code meant to be accessed via a browser? Then your URL's need to be within webspace, and not reflecting a file system path. Just for clarity, even with what you have, it's odd, and you introduce a space where you probably need a directory separator. If you are using interpolation, then use it. Maybe? echo "<a href='$latest_dir/$latest_file'><button>continue</button></a><br>"; With that said, this should only produce a url with a local filesystem path, and only usable by a browser in local mode, which is almost never what you want to be using PHP for.
-
Session information sharing on different subdomains
gizmola replied to Emsanator's topic in PHP Coding Help
I interpreted the question specifically to be someone with subdomains. So for example. www.mysite.com store.mysite.com It's pretty common to have setups like this, where you might want or need a session to be accessible to both subdomains. Since the main mechanism used to pass the session id is a cookie, restrictions on cookies are relevant. The default unless you change it, is to have the PHP session cookie set for the subdomain rather than the domain. The setup information provided was ostensibly code to change default session handling so that the session cookie is configured for all subdomains (.mysite.com) which would enable the reading and writing of session values by any subdomains of mysite.com. -
100% what requinix said. Unless there is some important reason you need to try and differentiate between "mobile" devices and whatever other client might be consuming your site, all that matters is that your site is responsive. It's probably just as important that your site looks good on large screens rather than designing to a one-size fits all mentality. min-width and max-width can be helpful. Some of that is using newer layout features like flexbox or grid, and avoiding fix sizes. Use em and rem for typography. learn about attributes relative to the viewport like vw, vh, vmin & vmax. learn about min-width and max-width style images with width: 100% so they expand and contract. learn and use flexbox and/or grid for your layout learn media queries and how to use them A basic example would be a nav bar styled using flexbox. With flexbox you would have a container/parent element like "nav" <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> CSS would be something like this: nav ul { list-style: none; padding: 0; font-size: 3rem; display: flex; justify-content: center; } nav li { margin-left: 2em; } nav a { text-decoration: none; color: #707070; font-weight: 700; padding: .25em 0; } nav a:hover, nav a:focus { color: lightblue; } @media (max-width: 650px) { nav ul { flex-direction: column; font-size: 1rem; } /* have to reset the margin for centered menu items */ nav li { margin: .5em 0; } } You can play with the max-width value here, but this illustrates a pretty standard technique of having a desktop layout that you then modify using one or more media queries, to change your desktop styles to something more mobile friendly. In this example, I have the nav with a default "row" orientation. The li items are centered and layout in a row across the screen. When the width of the browser is shrunk below the threshold of 650px wide, I change the "nav ul" flex-direction to "column" which causes the li items in the nav to be in a column. I also reduce the font-size and change the margin property so the text is no longer centered. This is a very simple example, but it should give you a jumpstart into what "responsive" design offers.
-
No worries my friend, your passion and desire to produce is very evident, and speaking for most of the regulars here, we invest time here to try and help people like yourself who are working hard at building up their expertise.
-
I am doing the same as @requinix. I also paid the $15 fee to get the registered/upgraded capabilities of Inteliphense. Just make sure you follow the instructions for the use of Inteliphense. Very worth it. Key thing to do after you install intelliphense: VSCode's built in Emmet support is a killer feature when you are writing a lot of html.
-
First off, does it matter whether or not a column is null or ''. The answer to that very much will dictate what you might need to do here. The difference between NULL and an empty string with mysql is an annoyance. Short answer: If you need to query for values in a column that are either NULL or not NULL, then your syntax needs to be different. The standard equality '=' check doesn't work. For example, looking for NULL values in a name column: SELECT * FROM test WHERE name = NULL; Will be empty. You have to use: SELECT * FROM test WHERE name IS NULL; However, if the value is an empty string: SELECT * FROM test WHERE name = '' Will work. In order to update a column to NULL you need to use the exact syntax of UPDATE asset set sale_stamp = null WHERE id = '17' You mention the "generated SQL". You don't specify what is generating the code. With that said, I would probably first try to see if setting the value of $sale_stamp to PHP null works. $sale_stamp = empty($_POST['sale_stamp']) ? null : $_POST['sale_stamp'];
-
Hi Leon, Some problems with your markup: Block elements already have a box around them. You don't want to nest an h1 inside a p for example: <p><h1 class="headline">Et godt eksempel på at det fungerer, er at IANA har godkjent særnorske tegn i domenenavn. Om det er noe som har slått til (blitt en suksess) er ett annet spørsmål. Du kan jo forsøke selv og se om det er noen norske butikker og firmaer som har registrert sitt firmanavn, for eksempel. www.elkjøp.no .</h1></p> Use something like this instead: <article class="article"> <h1>Title</h1> <p>Article text here ........ </p> </article> Hey let me suggest to you a methodology for css naming and specificity I really like: BEM. CSS can easily have specificity issues, and can also make your page structure brittle. One thing you are doing that is not great, is to use div.class in your css. That's just a bad idea. Rules of thumb are these: Never use ID's for selectors Don't select by tags for any complex selectors Give everything you want to style its own class So with BEM you want to step back and look at your "blocks" What are they from a structural level? From what I can see your outline should have started with something like this: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Site Title</title> <link rel="stylesheet" href="style.css"> </head> <body class="body"> <header class="header"> <!-- Logo Top Menu nested here--> </header> <div class="body__container"> <section class="menu"> <!-- Menu block here --> </section> <main class="main"> <article class="main__article main__article--primary"> <h1 class="main__headline">Hva ligger bakenfor?</h1> <p class="main__content">Organisasjoner som setter standarder for drift, bruk og utvikling av internett.</p> </article> <article class="main__article"> <h1 class="main__headline">...</h1> <p class="main__content">...</p> </article> </main> </div> <footer class="footer">Footer Stuff Nested here</footer> </body> </html> I would take a step back from what you are doing and make sure you have a clean block structure. With BEM, you make a class for each semantic block. You should remove all those div.class selectors. Make a css class for every block, element and element--modifier you see, and add any additional ones you need for menus etc. .body { } .body__container { } .menu { } .menu__button { } .menu__title { } .menu__text { } .menu__link { } etc. For the menu, usually people will use either a ul with nested li items, or a bunch of buttons inside a section. <section class="menu"> <div class="menu__title">Naviger</div> <a class="menu__link" href="index.php" title="Tilbake til Start"> <button class="menu__button"> <span class="menu__text">Hjem</span> </button> </a> <!-- other menu items the same --> </section>
-
There are many ways to accomplish this. What approach have you attempted so far? HTML tables Flexbox Grid One fundamental technique for procedural programming, when looping through a set of data, is to utilize the modulus operator. By checking the remainder of division by the number of items you want per row, you can determine whether or not to start a new line, or whether a new line was just started. Consider this code that has a simulated result set of rows: <?php define('PER_ROW', 3); $resultset[] = array('id' => 3, 'name' => 'Bob'); $resultset[] = array('id' => 5, 'name' => 'Mark'); $resultset[] = array('id' => 9, 'name' => 'Sam'); $resultset[] = array('id' => 10, 'name' => 'Linda'); $resultset[] = array('id' => 11, 'name' => 'Amy'); $resultset[] = array('id' => 75, 'name' => 'John'); $resultset[] = array('id' => 20, 'name' => 'Aaron'); $resultset[] = array('id' => 19, 'name' => 'Ringo'); $resultset[] = array('id' => 2, 'name' => 'Paul'); $resultset[] = array('id' => 99, 'name' => 'George'); foreach ($resultset as $key => $row) { $key++; if ($key % PER_ROW === 1) { // First item in row echo "| "; } echo "{$row['id']}: {$row['name']} | "; if ($key % PER_ROW === 0) { // Last item in row echo PHP_EOL; } } echo PHP_EOL; You can play with this example here: https://3v4l.org/lD83M Changing the PER_ROW constant to another number like 4 for example, should help you see how this common technique works.
-
how to resolve errors like this in php 8 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\AplikasiInventaris\admin\detailpinjam.php on line 7 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\A
gizmola replied to sandi123's topic in PHP Coding Help
One reason I keep coming back to the forum, is that there are times when someone uses some syntax or a function or technique I'm not familiar with or wouldn't have thought to use. Seeing what other people offer as a solution to questions is a nice diversion and helps keep the learning process fresh. -
This is the expected behavior. YOu have declared that the content_box has a width of 950px. So at the point that it can not fit side by side with the menu_box div. I'm not sure what you are going for, because the typical way to handle responsiveness down to mobile sizes is to use a media query and do something to hide the menu, perhaps with the display of a hamburger widget. If you want to keep these divs side by side, then I would suggest you use flexbox instead. With Flexbox, you need a parent container for the columns you want to orientate. There are many layout options possible with flexbox, so I leave that to you, but you can see from this demo that this performs more inline with your expectations. Rather than use a fixed width for your content div, I used 80%, but you can also see how flexbox handles expanding or shrinking. Test Markup <div class="content"> <div class="menu_box"> <ul> <li>Home</li> <li>Item1</li> <li>Item2</li> </ul> </div> <div class="content_box"> <h1>Content Box</h1> </div> </div> CSS div.content { display: flex; } div.menu_box { color: #008833; margin-top: 0px; margin-left: 10px; width: 165px; /*max-height; 100px;*/ height: 300px; /*border: solid 1px;*/ /*border-color: #ffcc99;*/ /*border-radius: 5px;*/ background: gray; } div.content_box { margin-left: auto; margin-right: auto; margin-top: 5px; width: 80%; max-height: 100%; margin: auto; border: solid 1px; border-color: #ffcc99; border-radius: 5px; background: blue; } Codepen based on your original code, with some background colors to see something: https://codepen.io/gizmola/pen/xxXMwLP
-
You will need to develop techniques within your search engine to determine if a site is adult and not include that in your results.
-
how to resolve errors like this in php 8 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\AplikasiInventaris\admin\detailpinjam.php on line 7 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\A
gizmola replied to sandi123's topic in PHP Coding Help
I like @ginerjm's advice a lot. One thing I would add to it is that you should use empty() to check for a variable that may or may not be set. if (empty($_GET['id'])) $errmsg .= 'Missing id value<br>'; else -
how to resolve errors like this in php 8 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\AplikasiInventaris\admin\detailpinjam.php on line 7 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\A
gizmola replied to sandi123's topic in PHP Coding Help
I agree with everything @mac_gyverwrote. Please use the "<>" button to paste in your code in the future. As to the error, it is telling you that you are trying to reference a key in an array, but the variable isn't an array at all, it is the null value. Since it is the result of the fetch() that pretty much tells you the fetch failed. -
print_r is a debugging tool, so you can evaluate the contents of variables on the path to your final solution. Array keys require either a numeric index, or a string key. If it's a string key, you need to put quotes around the key: $cert = openssl_x509_parse($_SERVER['SSL_CLIENT_CERT']); echo $cert['extensions']['subjectAltName'];
-
Hi Arend. I Don't know how long ago you did any PHP but much has changed. The biggest change is that any new project should involve the use of the Composer. https://getcomposer.org/ The language has a lot of new syntax and improvements, and it's also faster than it has ever been. PHP has 2 of the best MVC frameworks in the web development world in Symfony and Laravel. Most professional PHP developers are using phpStorm as their editor. With that said, for beginners and people who are coding as a hobby, I personally recommend Visual Studio Code with the Intelephense plugin. It's free, but there's an enhanced version license you can get for $15 that includes additional highly valuable features that make VSCode better for PHP development. It's very worth the small investment. You should learn about git and start using it. If you don't already have one make a github account. Here's a solid tutorial on the git basics you need to know, that I've reviewed and can recommend as providing a solid foundational understanding in 30 minutes.
-
I give your question a 1 out of 10 for presentation, and a 0 out of 10 for the material required to get you any sort of usable answer.
- 1 reply
-
- 1
-
-
I can't add an at command from php. Please help.
gizmola replied to SLSCoder's topic in PHP Coding Help
A couple of notes/suggestions for you: First, shell_exec is equivalent to using backtics, inherited from the bourne bash shell. $out = `echo mkdir /var/www/test | at now +1 minutes`; I can see you have a contrived example, but if you actually want to depend on os return codes from the command you have to use exec, as it allows for the passing of an optional return code parameter, which in many cases is probably a preferable way to determine whether your commands ran successfully or had errors. -
There shouldn't ever be a situation where a syntax error causes your page not to work, if you use a php aware editor that includes syntax checking/lint. Of course there are many other types of runtime errors that can happen, and those settings are good for development. There's also xdebug you can use for debugging, again with a modern PHP editor. The most popular commercial/pro editor is PHPStorm. If you want to go free, I'd suggest using Visual Studio Code, with some PHP plugins, like Inteliphense, PHP Debug and maybe one of the plugins that wrap formatting tools, php cs fixer as an example. You do have to figure out how to get plugins like that working with a local install of the formatting tool.
-
There are also CMS's and Forums that are easy to setup, already come with user authentication systems and ways to author and secure content. Wordpress, Drupal, phpBB, etc. come to mind.
-
Can someone help me use SSI.php to let users access a web page
gizmola replied to thirtywest's topic in PHP Coding Help
A little googling tells me there is nothing simple that will let you do this SMF Wordpress integration. SMF and Wordpress don't play well together, just looking at a few posts asking for something similar to what you want. There are bridge hacks for SMF that will "pump" user accounts into wordpress. These types of bridges are notoriously brittle, as changes to either side of the equation break them. There's also the matter of lots and lots of wordpress accounts, when typically you only want a few for you to author with. Another possible solution would be to protect the wordpress pages with a plugin like this one: https://wordpress.org/support/plugin/password-protect-page/ although it does some hacking with the wordpress user system that might be problematic. Using that plugin you could possibly integrate with it, or you could hack your own solution. In either case, it looks like the way to do it would be to write your own standalone php script that would utilize smf's SSI.php stuff to check authentication and grant access. You could think of this as your own primitive SMF REST api. You could call this from ajax you have in the wordpress page to allow or deny rendering of the wordpress content body. This would get you around a lot of complexity issues. While we do have a lot of PHP experts here, PHPFreaks hasn't personally used SMF in many years, although we did use it for a while, so I don't know that there is anyone active in the community that has much recent experience. I'd suggest focusing your efforts over at the SMF forum. Just be really clear about what you want to do, and how you intend to implement it. -
So, considering you also need to learn css, definitely make a scrimba account. They have free courses there on css from Kevin Powell who is a css authority and excellent teacher. Even if you decide to get a pro membership, it's pretty economical. The scrimba platform makes it easy to do the exercises without having to setup your own environment, but you can take code from it and use it in a "real" website setup. For source code management, use git. Git is pretty much the world standard for source code management now. Pluralsight has a course on it, but I can't vouch for it, but as you have the resource check it out. You also want to make a github account, which you can use to make repos for your projects. You can then setup your local git to use your github account as a remote and push your code there. I have done some git presentations in the past, and although it's just the slides, it might help you get a jumpstart on learning it. I can't say how long I'll leave this here, but for now there's a link to presentation converted to pdf.
-
I personally don't use printf/sprintf much either, but you make some good points. I also coded in c, before php was a thing, and those are wrappers around the standard c library afaik. They were there for c programmers coming to php to get up and running fast, but that's probably not a very substantial group anymore. I agree they do have some nice utility in many circumstances, especially where number formatting is important. If you are going to want/need localization, I doubt they are something you would still want to use though.